﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Resources;
using System.Windows.Forms;

namespace YArchitech.Controls.ImgListView
{
	[ToolboxBitmap(typeof(ImageListView))]
	[Description("Represents an image list view control.")]
	[DefaultEvent("ItemClick")]
	[DefaultProperty("Items")]
	[Designer(typeof(ImageListViewDesigner))]
	[DesignerSerializer(typeof(ImageListViewSerializer), typeof(CodeDomSerializer))]
	[Docking(DockingBehavior.Ask)]
	public class ImageListView : System.Windows.Forms.Control
	{
		[Category("Behavior")]
		[Description("Gets or sets whether column headers respond to mouse clicks.")]
		[DefaultValue(true)]
		public bool AllowColumnClick { get; set; }

		[Category("Behavior")]
		[Description("Gets or sets whether column headers can be resized with the mouse.")]
		[DefaultValue(true)]
		public bool AllowColumnResize { get; set; }

		[Category("Behavior")]
		[Description("Gets or sets whether the user can drag items for drag-and-drop operations.")]
		[DefaultValue(false)]
		public bool AllowDrag { get; set; }

		[Category("Behavior")]
		[Description("Gets or sets whether duplicate items (image files pointing to the same path on the file system) are allowed.")]
		[DefaultValue(false)]
		public bool AllowDuplicateFileNames { get; set; }

		[Category("Behavior")]
		[Description("Gets or sets whether the left-pane can be resized with the mouse.")]
		[DefaultValue(true)]
		public bool AllowPaneResize { get; set; }

		[Category("Appearance")]
		[Description("Gets or sets the background color of the control.")]
		[DefaultValue(typeof(System.Drawing.Color), "Window")]
		public override System.Drawing.Color BackColor
		{
			get
			{
				return base.BackColor;
			}
			set
			{
				base.BackColor = value;
				this.Refresh();
			}
		}

		[Category("Appearance")]
		[Description("Gets or sets the border style of the control.")]
		[DefaultValue(typeof(BorderStyle), "Fixed3D")]
		public BorderStyle BorderStyle
		{
			get
			{
				return this.mBorderStyle;
			}
			set
			{
				this.mBorderStyle = value;
				base.UpdateStyles();
			}
		}

		[Category("Behavior")]
		[Description("Gets or sets the cache mode.")]
		[DefaultValue(typeof(CacheMode), "OnDemand")]
		[RefreshProperties(RefreshProperties.All)]
		public CacheMode CacheMode
		{
			get
			{
				return this.mCacheMode;
			}
			set
			{
				if (this.mCacheMode != value)
				{
					this.mCacheMode = value;
					if (this.mCacheMode == CacheMode.Continuous)
					{
						this.mCacheLimitAsItemCount = 0;
						this.mCacheLimitAsMemory = 0L;
					}
					if (this.cacheManager != null)
					{
						this.cacheManager.CacheMode = this.mCacheMode;
					}
				}
			}
		}

		[Category("Behavior")]
		[Description("Gets or sets the cache limit as either the count of thumbnail images or the memory allocated for cache (e.g. 10MB).")]
		[DefaultValue("20MB")]
		[RefreshProperties(RefreshProperties.All)]
		public string CacheLimit
		{
			get
			{
				if (this.mCacheLimitAsMemory != 0L)
				{
					return (this.mCacheLimitAsMemory / 1024L / 1024L).ToString() + "MB";
				}
				return this.mCacheLimitAsItemCount.ToString();
			}
			set
			{
				int num = 0;
				this.mCacheMode = CacheMode.OnDemand;
				if ((value.EndsWith("MB", StringComparison.OrdinalIgnoreCase) && int.TryParse(value.Substring(0, value.Length - 2).Trim(), out num)) || (value.EndsWith("MiB", StringComparison.OrdinalIgnoreCase) && int.TryParse(value.Substring(0, value.Length - 3).Trim(), out num)))
				{
					this.mCacheLimitAsItemCount = 0;
					this.mCacheLimitAsMemory = (long)(num * 1024 * 1024);
					if (this.cacheManager != null)
					{
						this.cacheManager.CacheLimitAsMemory = this.mCacheLimitAsMemory;
						return;
					}
				}
				else
				{
					if (!int.TryParse(value, out num))
					{
						throw new ArgumentException("Cache limit must be specified as either the count of thumbnail images or the memory allocated for cache (eg 10MB)", "value");
					}
					this.mCacheLimitAsMemory = 0L;
					this.mCacheLimitAsItemCount = num;
					if (this.cacheManager != null)
					{
						this.cacheManager.CacheLimitAsItemCount = this.mCacheLimitAsItemCount;
						return;
					}
				}
			}
		}

		[Category("Appearance")]
		[Description("Gets the collection of columns of the image list view.")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public ImageListView.ImageListViewColumnHeaderCollection Columns
		{
			get
			{
				return this.mColumns;
			}
			internal set
			{
				this.mColumns = value;
				this.Refresh();
			}
		}

		[Category("Appearance")]
		[Description("Gets or sets the placeholder image.")]
		public Image DefaultImage
		{
			get
			{
				return this.mDefaultImage;
			}
			set
			{
				this.mDefaultImage = value;
				this.Refresh();
			}
		}

		[Category("Appearance")]
		[Browsable(false)]
		[Description("Gets the rectangle that represents the display area of the control.")]
		public override System.Drawing.Rectangle DisplayRectangle
		{
			get
			{
				return this.layoutManager.ClientArea;
			}
		}

		[Category("Appearance")]
		[Description("Gets or sets the error image.")]
		public Image ErrorImage
		{
			get
			{
				return this.mErrorImage;
			}
			set
			{
				this.mErrorImage = value;
				this.Refresh();
			}
		}

		[Category("Appearance")]
		[Description("Gets or sets the font of the column headers.")]
		[DefaultValue(typeof(Font), "Microsoft Sans Serif; 8.25pt")]
		public Font HeaderFont
		{
			get
			{
				return this.mHeaderFont;
			}
			set
			{
				if (this.mHeaderFont != null)
				{
					this.mHeaderFont.Dispose();
				}
				this.mHeaderFont = (Font)value.Clone();
				this.Refresh();
			}
		}

		[Browsable(false)]
		[Category("Behavior")]
		[Description("Gets the collection of items contained in the image list view.")]
		public ImageListView.ImageListViewItemCollection Items
		{
			get
			{
				return this.mItems;
			}
		}

		[Category("Appearance")]
		[Description("Gets or sets the width of the left pane.")]
		[DefaultValue(240)]
		public int PaneWidth
		{
			get
			{
				return this.mPaneWidth;
			}
			set
			{
				if (this.mPaneWidth != value)
				{
					if (this.mPaneWidth < 2)
					{
						this.mPaneWidth = 2;
					}
					this.mPaneWidth = value;
					this.Refresh();
				}
			}
		}

		[Category("Behavior")]
		[Description("Gets or sets whether the control will retry loading thumbnails on an error.")]
		[DefaultValue(true)]
		public bool RetryOnError
		{
			get
			{
				return this.mRetryOnError;
			}
			set
			{
				this.mRetryOnError = value;
				if (this.cacheManager != null)
				{
					this.cacheManager.RetryOnError = this.mRetryOnError;
				}
			}
		}

		[Browsable(false)]
		[Category("Behavior")]
		[Description("Gets the collection of selected items contained in the image list view.")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public ImageListView.ImageListViewSelectedItemCollection SelectedItems
		{
			get
			{
				return this.mSelectedItems;
			}
		}

		[Category("Appearance")]
		[DefaultValue(typeof(ColumnType), "Name")]
		[Description("Gets or sets the sort column.")]
		public ColumnType SortColumn
		{
			get
			{
				return this.mSortColumn;
			}
			set
			{
				if (value != this.mSortColumn)
				{
					this.mSortColumn = value;
					this.Sort();
				}
			}
		}

		[Category("Appearance")]
		[DefaultValue(typeof(SortOrder), "None")]
		[Description("Gets or sets the sort order.")]
		public SortOrder SortOrder
		{
			get
			{
				return this.mSortOrder;
			}
			set
			{
				if (value != this.mSortOrder)
				{
					this.mSortOrder = value;
					this.Sort();
				}
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		[Browsable(false)]
		[Bindable(false)]
		[DefaultValue(null)]
		public override string Text { get; set; }

		[Category("Appearance")]
		[Description("Gets or sets the size of image thumbnails.")]
		[DefaultValue(typeof(Size), "96,96")]
		public Size ThumbnailSize
		{
			get
			{
				return this.mThumbnailSize;
			}
			set
			{
				if (this.mThumbnailSize != value)
				{
					this.mThumbnailSize = value;
					this.cacheManager.Clear();
					this.Refresh();
				}
			}
		}

		[Category("Behavior")]
		[Description("Gets or sets the embedded thumbnails extraction behavior.")]
		[DefaultValue(typeof(UseEmbeddedThumbnails), "Auto")]
		public UseEmbeddedThumbnails UseEmbeddedThumbnails
		{
			get
			{
				return this.mUseEmbeddedThumbnails;
			}
			set
			{
				if (this.mUseEmbeddedThumbnails != value)
				{
					this.mUseEmbeddedThumbnails = value;
					this.cacheManager.Clear();
					this.Refresh();
				}
			}
		}

		[Category("Appearance")]
		[Description("Gets or sets the view mode of the image list view.")]
		[DefaultValue(typeof(Autodesk.Revit.DB.View), "Thumbnails")]
		public Autodesk.Revit.DB.View View
		{
			get
			{
				return this.mView;
			}
			set
			{
				this.mRenderer.SuspendPaint();
				int firstVisible = this.layoutManager.FirstVisible;
				this.mView = value;
				this.layoutManager.Update();
				this.EnsureVisible(firstVisible);
				this.Refresh();
				this.mRenderer.ResumePaint();
			}
		}

		internal System.Drawing.Point ViewOffset
		{
			get
			{
				return this.mViewOffset;
			}
			set
			{
				this.mViewOffset = value;
			}
		}

		internal ScrollOrientation ScrollOrientation
		{
			get
			{
				if (this.mView != Autodesk.Revit.DB.View.Gallery)
				{
					return ScrollOrientation.VerticalScroll;
				}
				return ScrollOrientation.HorizontalScroll;
			}
		}

		protected override CreateParams CreateParams
		{
			get
			{
				CreateParams createParams = base.CreateParams;
				createParams.Style &= -8388609;
				createParams.ExStyle &= -513;
				if (this.mBorderStyle == BorderStyle.Fixed3D)
				{
					createParams.ExStyle |= 512;
				}
				else if (this.mBorderStyle == BorderStyle.FixedSingle)
				{
					createParams.Style |= 8388608;
				}
				return createParams;
			}
		}

		public ImageListView()
		{
			this.SetRenderer(new ImageListView.ImageListViewRenderer());
			this.AllowColumnClick = true;
			this.AllowColumnResize = true;
			this.AllowDrag = false;
			this.AllowDuplicateFileNames = false;
			this.AllowPaneResize = true;
			this.BackColor = SystemColors.Window;
			this.mBorderStyle = BorderStyle.Fixed3D;
			this.mCacheMode = CacheMode.OnDemand;
			this.mCacheLimitAsItemCount = 0;
			this.mCacheLimitAsMemory = 20971520L;
			this.mColumns = new ImageListView.ImageListViewColumnHeaderCollection(this);
			ResourceManager resourceManager = new ResourceManager("Manina.Windows.Forms.ImageListViewResources", Assembly.GetExecutingAssembly());
			this.mDefaultImage = (resourceManager.GetObject("DefaultImage") as Image);
			this.mErrorImage = (resourceManager.GetObject("ErrorImage") as Image);
			this.HeaderFont = this.Font;
			this.mItems = new ImageListView.ImageListViewItemCollection(this);
			this.mPaneWidth = 240;
			this.mRetryOnError = true;
			this.mSelectedItems = new ImageListView.ImageListViewSelectedItemCollection(this);
			this.mSortColumn = ColumnType.Name;
			this.mSortOrder = SortOrder.None;
			base.SetStyle(ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.Selectable | ControlStyles.UserMouse | ControlStyles.AllPaintingInWmPaint, true);
			this.Text = string.Empty;
			this.mThumbnailSize = new Size(96, 96);
			this.mUseEmbeddedThumbnails = UseEmbeddedThumbnails.Auto;
			this.mView = Autodesk.Revit.DB.View.Thumbnails;
			this.mViewOffset = new System.Drawing.Point(0, 0);
			this.hScrollBar = new HScrollBar();
			this.vScrollBar = new VScrollBar();
			this.hScrollBar.Visible = false;
			this.vScrollBar.Visible = false;
			this.hScrollBar.Scroll += this.hScrollBar_Scroll;
			this.vScrollBar.Scroll += this.vScrollBar_Scroll;
			this.layoutManager = new ImageListViewLayoutManager(this);
			this.forceRefresh = false;
			this.navigationManager = new ImageListView.ImageListViewNavigationManager(this);
			this.cacheManager = new ImageListViewCacheManager(this);
			this.itemCacheManager = new ImageListViewItemCacheManager(this);
			this.disposed = false;
		}

		public void ClearThumbnailCache()
		{
			this.cacheManager.Clear();
			this.Refresh();
		}

		public new void SuspendLayout()
		{
			base.SuspendLayout();
			this.mRenderer.SuspendPaint(true);
		}

		public new void ResumeLayout()
		{
			this.ResumeLayout(false);
		}

		public new void ResumeLayout(bool performLayout)
		{
			base.ResumeLayout(performLayout);
			if (performLayout)
			{
				this.Refresh();
			}
			this.mRenderer.ResumePaint(true);
		}

		public void SetColumnHeader(ColumnType type, string text, int width, int displayIndex, bool visible)
		{
			this.mRenderer.SuspendPaint();
			ImageListView.ImageListViewColumnHeader imageListViewColumnHeader = this.Columns[type];
			imageListViewColumnHeader.Text = text;
			imageListViewColumnHeader.Width = width;
			imageListViewColumnHeader.DisplayIndex = displayIndex;
			imageListViewColumnHeader.Visible = visible;
			this.Refresh();
			this.mRenderer.ResumePaint();
		}

		public void SetColumnHeader(ColumnType type, int width, int displayIndex, bool visible)
		{
			this.mRenderer.SuspendPaint();
			ImageListView.ImageListViewColumnHeader imageListViewColumnHeader = this.Columns[type];
			imageListViewColumnHeader.Width = width;
			imageListViewColumnHeader.DisplayIndex = displayIndex;
			imageListViewColumnHeader.Visible = visible;
			this.Refresh();
			this.mRenderer.ResumePaint();
		}

		public void SetRenderer(ImageListView.ImageListViewRenderer renderer)
		{
			if (renderer == null)
			{
				throw new System.ArgumentNullException("renderer");
			}
			if (this.mRenderer != null)
			{
				this.mRenderer.Dispose();
			}
			this.mRenderer = renderer;
			this.mRenderer.mImageListView = this;
			if (this.layoutManager != null)
			{
				this.layoutManager.Update(true);
			}
			this.Refresh();
		}

		public void Sort()
		{
			this.mItems.Sort();
			this.Refresh();
		}

		public void SelectAll()
		{
			this.mRenderer.SuspendPaint();
			foreach (ImageListViewItem imageListViewItem in this.Items)
			{
				imageListViewItem.mSelected = true;
			}
			this.OnSelectionChangedInternal();
			this.Refresh();
			this.mRenderer.ResumePaint();
		}

		public void ClearSelection()
		{
			this.mRenderer.SuspendPaint();
			this.mSelectedItems.Clear();
			this.Refresh();
			this.mRenderer.ResumePaint();
		}

		public void HitTest(System.Drawing.Point pt, out ImageListView.HitInfo hitInfo)
		{
			if (this.View == Autodesk.Revit.DB.View.Details && pt.Y <= this.mRenderer.MeasureColumnHeaderHeight())
			{
				int num = 0;
				int num2 = this.layoutManager.ColumnHeaderBounds.Left;
				ColumnType columnType = (ColumnType)(-1);
				ColumnType columnSeparator = (ColumnType)(-1);
				foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in this.Columns.GetDisplayedColumns())
				{
					if (pt.X >= num2 && pt.X < num2 + imageListViewColumnHeader.Width + 6)
					{
						columnType = imageListViewColumnHeader.Type;
					}
					if (pt.X > num2 + imageListViewColumnHeader.Width - 6 && pt.X < num2 + imageListViewColumnHeader.Width + 6)
					{
						columnSeparator = imageListViewColumnHeader.Type;
					}
					if (columnType != (ColumnType)(-1))
					{
						break;
					}
					num2 += imageListViewColumnHeader.Width;
					num++;
				}
				hitInfo = new ImageListView.HitInfo(columnType, columnSeparator);
				return;
			}
			if (this.View == Autodesk.Revit.DB.View.Pane && pt.X <= this.mPaneWidth)
			{
				bool paneBorder = pt.X >= this.mPaneWidth - 4;
				hitInfo = new ImageListView.HitInfo(paneBorder);
				return;
			}
			int itemIndex = -1;
			pt.X -= this.layoutManager.ItemAreaBounds.Left;
			pt.Y -= this.layoutManager.ItemAreaBounds.Top;
			if (pt.X > 0 && pt.Y > 0)
			{
				int num3 = (pt.X + this.mViewOffset.X) / this.layoutManager.ItemSizeWithMargin.Width;
				int num4 = (pt.Y + this.mViewOffset.Y) / this.layoutManager.ItemSizeWithMargin.Height;
				if (this.ScrollOrientation == ScrollOrientation.HorizontalScroll || (this.ScrollOrientation == ScrollOrientation.VerticalScroll && num3 <= this.layoutManager.Cols))
				{
					int num5 = num4 * this.layoutManager.Cols + num3;
					if (num5 >= 0 && num5 <= this.Items.Count - 1 && this.layoutManager.GetItemBounds(num5).Contains(pt.X + this.layoutManager.ItemAreaBounds.Left, pt.Y + this.layoutManager.ItemAreaBounds.Top))
					{
						itemIndex = num5;
					}
				}
			}
			hitInfo = new ImageListView.HitInfo(itemIndex);
		}

		public bool EnsureVisible(int itemIndex)
		{
			if (itemIndex == -1)
			{
				return false;
			}
			if (this.Items.Count == 0)
			{
				return false;
			}
			System.Drawing.Rectangle itemAreaBounds = this.layoutManager.ItemAreaBounds;
			System.Drawing.Rectangle itemBounds = this.layoutManager.GetItemBounds(itemIndex);
			if (!itemAreaBounds.Contains(itemBounds))
			{
				if (this.ScrollOrientation == ScrollOrientation.HorizontalScroll)
				{
					int num;
					if (itemBounds.Left < itemAreaBounds.Left)
					{
						num = itemAreaBounds.Left - itemBounds.Left;
					}
					else
					{
						int num2 = itemIndex - (this.layoutManager.Cols - 1) * this.layoutManager.Rows;
						if (num2 < 0)
						{
							num2 = 0;
						}
						num = itemAreaBounds.Left - this.layoutManager.GetItemBounds(num2).Left;
					}
					int num3 = this.mViewOffset.X - num;
					if (num3 > this.hScrollBar.Maximum - this.hScrollBar.LargeChange + 1)
					{
						num3 = this.hScrollBar.Maximum - this.hScrollBar.LargeChange + 1;
					}
					if (num3 < this.hScrollBar.Minimum)
					{
						num3 = this.hScrollBar.Minimum;
					}
					this.mViewOffset.X = num3;
					this.mViewOffset.Y = 0;
					this.hScrollBar.Value = num3;
					this.vScrollBar.Value = 0;
				}
				else
				{
					int num4;
					if (itemBounds.Top < itemAreaBounds.Top)
					{
						num4 = itemAreaBounds.Top - itemBounds.Top;
					}
					else
					{
						int num5 = itemIndex - (this.layoutManager.Rows - 1) * this.layoutManager.Cols;
						if (num5 < 0)
						{
							num5 = 0;
						}
						num4 = itemAreaBounds.Top - this.layoutManager.GetItemBounds(num5).Top;
					}
					int num6 = this.mViewOffset.Y - num4;
					if (num6 > this.vScrollBar.Maximum - this.vScrollBar.LargeChange + 1)
					{
						num6 = this.vScrollBar.Maximum - this.vScrollBar.LargeChange + 1;
					}
					if (num6 < this.vScrollBar.Minimum)
					{
						num6 = this.vScrollBar.Minimum;
					}
					this.mViewOffset.X = 0;
					this.mViewOffset.Y = num6;
					this.hScrollBar.Value = 0;
					this.vScrollBar.Value = num6;
				}
				this.Refresh();
				return true;
			}
			return false;
		}

		public ItemVisibility IsItemVisible(ImageListViewItem item)
		{
			return this.IsItemVisible(item.Index);
		}

		internal void Refresh(bool force)
		{
			this.forceRefresh = force;
			this.Refresh();
			this.forceRefresh = false;
		}

		internal bool IsItemVisible(Guid guid)
		{
			return this.layoutManager.IsItemVisible(guid);
		}

		internal ItemVisibility IsItemVisible(int itemIndex)
		{
			if (this.mItems.Count == 0)
			{
				return ItemVisibility.NotVisible;
			}
			if (itemIndex < 0 || itemIndex > this.mItems.Count - 1)
			{
				return ItemVisibility.NotVisible;
			}
			if (itemIndex < this.layoutManager.FirstPartiallyVisible || itemIndex > this.layoutManager.LastPartiallyVisible)
			{
				return ItemVisibility.NotVisible;
			}
			if (itemIndex >= this.layoutManager.FirstVisible && itemIndex <= this.layoutManager.LastVisible)
			{
				return ItemVisibility.Visible;
			}
			return ItemVisibility.PartiallyVisible;
		}

		internal Dictionary<Guid, bool> GetVisibleItems()
		{
			Dictionary<Guid, bool> dictionary = new Dictionary<Guid, bool>();
			if (this.layoutManager.FirstPartiallyVisible != -1 && this.layoutManager.LastPartiallyVisible != -1)
			{
				int num = this.layoutManager.FirstPartiallyVisible;
				int num2 = this.layoutManager.LastPartiallyVisible;
				num -= this.layoutManager.Cols * this.layoutManager.Rows;
				num2 += this.layoutManager.Cols * this.layoutManager.Rows;
				num = Math.Min(this.mItems.Count - 1, Math.Max(0, num));
				num2 = Math.Min(this.mItems.Count - 1, Math.Max(0, num2));
				for (int i = num; i <= num2; i++)
				{
					dictionary.Add(this.mItems[i].Guid, false);
				}
			}
			return dictionary;
		}

		protected override void OnCreateControl()
		{
			base.OnCreateControl();
			base.Size = new Size(120, 100);
			if (!base.Controls.Contains(this.hScrollBar))
			{
				base.Controls.Add(this.hScrollBar);
				base.Controls.Add(this.vScrollBar);
			}
		}

		protected override void OnDragOver(DragEventArgs e)
		{
			this.navigationManager.DragOver(e);
			base.OnDragOver(e);
		}

		protected override void OnDragEnter(DragEventArgs e)
		{
			this.navigationManager.DragEnter(e);
			base.OnDragEnter(e);
		}

		protected override void OnDragLeave(EventArgs e)
		{
			this.navigationManager.DragLeave();
			base.OnDragLeave(e);
		}

		protected override void OnDragDrop(DragEventArgs e)
		{
			this.navigationManager.DragDrop(e);
			base.OnDragDrop(e);
		}

		private void vScrollBar_Scroll(object sender, ScrollEventArgs e)
		{
			this.mViewOffset.Y = e.NewValue;
			this.Refresh();
		}

		private void hScrollBar_Scroll(object sender, ScrollEventArgs e)
		{
			this.mViewOffset.X = e.NewValue;
			this.Refresh();
		}

		protected override void OnResize(EventArgs e)
		{
			base.OnResize(e);
			if (!this.disposed && this.mRenderer != null)
			{
				this.mRenderer.RecreateBuffer();
			}
			if (this.hScrollBar == null)
			{
				return;
			}
			this.layoutManager.Update();
			this.Refresh();
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			if (!this.disposed && this.mRenderer != null)
			{
				this.mRenderer.Refresh(e.Graphics, this.forceRefresh);
			}
		}

		protected override void OnMouseDown(MouseEventArgs e)
		{
			if (!this.Focused && (e.Button & MouseButtons.Right) == MouseButtons.Right)
			{
				base.Focus();
			}
			this.navigationManager.MouseDown(e);
			base.OnMouseDown(e);
		}

		protected override void OnMouseUp(MouseEventArgs e)
		{
			this.navigationManager.MouseUp(e);
			base.OnMouseUp(e);
		}

		protected override void OnMouseMove(MouseEventArgs e)
		{
			this.navigationManager.MouseMove(e);
			base.OnMouseMove(e);
		}

		protected override void OnMouseWheel(MouseEventArgs e)
		{
			this.mRenderer.SuspendPaint();
			if (this.ScrollOrientation == ScrollOrientation.VerticalScroll)
			{
				int num = this.mViewOffset.Y - e.Delta / 120 * this.vScrollBar.SmallChange;
				if (num > this.vScrollBar.Maximum - this.vScrollBar.LargeChange + 1)
				{
					num = this.vScrollBar.Maximum - this.vScrollBar.LargeChange + 1;
				}
				if (num < 0)
				{
					num = 0;
				}
				if (num < this.vScrollBar.Minimum)
				{
					num = this.vScrollBar.Minimum;
				}
				if (num > this.vScrollBar.Maximum)
				{
					num = this.vScrollBar.Maximum;
				}
				this.mViewOffset.Y = num;
				this.vScrollBar.Value = num;
			}
			else
			{
				int num2 = this.mViewOffset.X - e.Delta / 120 * this.hScrollBar.SmallChange;
				if (num2 > this.hScrollBar.Maximum - this.hScrollBar.LargeChange + 1)
				{
					num2 = this.hScrollBar.Maximum - this.hScrollBar.LargeChange + 1;
				}
				if (num2 < 0)
				{
					num2 = 0;
				}
				if (num2 < this.hScrollBar.Minimum)
				{
					num2 = this.hScrollBar.Minimum;
				}
				if (num2 > this.hScrollBar.Maximum)
				{
					num2 = this.hScrollBar.Maximum;
				}
				this.mViewOffset.X = num2;
				this.hScrollBar.Value = num2;
			}
			this.Refresh(true);
			this.mRenderer.ResumePaint();
			base.OnMouseWheel(e);
		}

		protected override void OnMouseLeave(EventArgs e)
		{
			this.navigationManager.MouseLeave();
			base.OnMouseLeave(e);
		}

		protected override void OnMouseDoubleClick(MouseEventArgs e)
		{
			this.navigationManager.MouseDoubleClick(e);
			base.OnMouseDoubleClick(e);
		}

		protected override bool IsInputKey(Keys keyData)
		{
			return (keyData & Keys.Left) == Keys.Left || (keyData & Keys.Right) == Keys.Right || (keyData & Keys.Up) == Keys.Up || (keyData & Keys.Down) == Keys.Down || base.IsInputKey(keyData);
		}

		protected override void OnKeyDown(KeyEventArgs e)
		{
			this.navigationManager.KeyDown(e);
			base.OnKeyDown(e);
		}

		protected override void OnKeyUp(KeyEventArgs e)
		{
			this.navigationManager.KeyUp(e);
			base.OnKeyUp(e);
		}

		protected override void OnGotFocus(EventArgs e)
		{
			base.OnGotFocus(e);
			this.Refresh();
		}

		protected override void OnLostFocus(EventArgs e)
		{
			base.OnLostFocus(e);
			this.Refresh();
		}

		protected override void OnHandleDestroyed(EventArgs e)
		{
			this.cacheManager.Stop();
			this.itemCacheManager.Stop();
		}

		protected override void Dispose(bool disposing)
		{
			if (!this.disposed)
			{
				if (disposing)
				{
					if (this.mRenderer != null)
					{
						this.mRenderer.Dispose();
					}
					if (this.mHeaderFont != null)
					{
						this.mHeaderFont.Dispose();
					}
					this.cacheManager.Dispose();
					this.itemCacheManager.Dispose();
					this.navigationManager.Dispose();
				}
				this.disposed = true;
			}
			base.Dispose(disposing);
		}

		protected virtual void OnDropFiles(DropFileEventArgs e)
		{
			if (this.DropFiles != null)
			{
				this.DropFiles(this, e);
			}
			if (e.Cancel)
			{
				return;
			}
			int num = e.Index;
			int num2 = 0;
			this.mSelectedItems.Clear(false);
			string[] fileNames = e.FileNames;
			for (int i = 0; i < fileNames.Length; i++)
			{
				ImageListViewItem imageListViewItem = new ImageListViewItem(fileNames[i]);
				imageListViewItem.mSelected = true;
				this.mItems.InsertInternal(num, imageListViewItem);
				if (num2 == 0)
				{
					num2 = imageListViewItem.Index;
				}
				num++;
			}
			this.EnsureVisible(num2);
			this.OnSelectionChangedInternal();
		}

		protected virtual void OnColumnWidthChanged(ColumnEventArgs e)
		{
			if (this.ColumnWidthChanged != null)
			{
				this.ColumnWidthChanged(this, e);
			}
		}

		protected virtual void OnColumnClick(ColumnClickEventArgs e)
		{
			if (this.ColumnClick != null)
			{
				this.ColumnClick(this, e);
			}
		}

		protected virtual void OnColumnHover(ColumnHoverEventArgs e)
		{
			if (this.ColumnHover != null)
			{
				this.ColumnHover(this, e);
			}
		}

		protected virtual void OnItemClick(ItemClickEventArgs e)
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, e);
			}
		}

		protected virtual void OnItemHover(ItemHoverEventArgs e)
		{
			if (this.ItemHover != null)
			{
				this.ItemHover(this, e);
			}
		}

		protected virtual void OnItemDoubleClick(ItemClickEventArgs e)
		{
			if (this.ItemDoubleClick != null)
			{
				this.ItemDoubleClick(this, e);
			}
		}

		protected virtual void OnSelectionChanged(EventArgs e)
		{
			if (this.SelectionChanged != null)
			{
				this.SelectionChanged(this, e);
			}
		}

		internal void OnSelectionChangedInternal()
		{
			this.OnSelectionChanged(new EventArgs());
		}

		protected virtual void OnThumbnailCached(ThumbnailCachedEventArgs e)
		{
			if (this.ThumbnailCached != null)
			{
				this.ThumbnailCached(this, e);
			}
		}

		internal void OnThumbnailCachedInternal(Guid guid, bool error)
		{
			int num = this.Items.IndexOf(guid);
			if (num != -1)
			{
				this.OnThumbnailCached(new ThumbnailCachedEventArgs(this.Items[num], error));
			}
		}

		internal void OnRefreshInternal()
		{
			this.Refresh();
		}

		internal void UpdateItemDetailsInternal(ImageListViewItem item, Utility.ShellImageFileInfo info)
		{
			item.UpdateDetailsInternal(info);
		}

		internal void UpdateItemDetailsInternal(ImageListViewItem item, VirtualItemDetailsEventArgs info)
		{
			item.UpdateDetailsInternal(info);
		}

		protected virtual void OnThumbnailCaching(ItemEventArgs e)
		{
			if (this.ThumbnailCaching != null)
			{
				this.ThumbnailCaching(this, e);
			}
		}

		protected virtual void OnRetrieveVirtualItemThumbnail(VirtualItemThumbnailEventArgs e)
		{
			if (this.RetrieveVirtualItemThumbnail != null)
			{
				this.RetrieveVirtualItemThumbnail(this, e);
			}
		}

		protected virtual void OnRetrieveVirtualItemImage(VirtualItemImageEventArgs e)
		{
			if (this.RetrieveVirtualItemImage != null)
			{
				this.RetrieveVirtualItemImage(this, e);
			}
		}

		protected virtual void OnRetrieveVirtualItemDetails(VirtualItemDetailsEventArgs e)
		{
			if (this.RetrieveVirtualItemDetails != null)
			{
				this.RetrieveVirtualItemDetails(this, e);
			}
		}

		internal virtual void RetrieveVirtualItemThumbnailInternal(VirtualItemThumbnailEventArgs e)
		{
			this.OnRetrieveVirtualItemThumbnail(e);
		}

		internal virtual void RetrieveVirtualItemImageInternal(VirtualItemImageEventArgs e)
		{
			this.OnRetrieveVirtualItemImage(e);
		}

		internal virtual void RetrieveVirtualItemDetailsInternal(VirtualItemDetailsEventArgs e)
		{
			this.OnRetrieveVirtualItemDetails(e);
		}

		[Category("Drag Drop")]
		[Browsable(true)]
		[Description("Occurs after the user drops files on to the control.")]
		public event DropFilesEventHandler DropFiles;

		[Category("Action")]
		[Browsable(true)]
		[Description("Occurs after the user successfully resized a column header.")]
		public event ColumnWidthChangedEventHandler ColumnWidthChanged;

		[Category("Action")]
		[Browsable(true)]
		[Description("Occurs when the user clicks a column header.")]
		public event ColumnClickEventHandler ColumnClick;

		[Category("Action")]
		[Browsable(true)]
		[Description("Occurs when the user moves the mouse over (and out of) a column header.")]
		public event ColumnHoverEventHandler ColumnHover;

		[Category("Action")]
		[Browsable(true)]
		[Description("Occurs when the user clicks an item.")]
		public event ItemClickEventHandler ItemClick;

		[Category("Action")]
		[Browsable(true)]
		[Description("Occurs when the user moves the mouse over (and out of) an item.")]
		public event ItemHoverEventHandler ItemHover;

		[Category("Action")]
		[Browsable(true)]
		[Description("Occurs when the user double-clicks an item.")]
		public event ItemDoubleClickEventHandler ItemDoubleClick;

		[Category("Behavior")]
		[Browsable(true)]
		[Description("Occurs when the selected items collection changes.")]
		public event EventHandler SelectionChanged;

		[Category("Behavior")]
		[Browsable(true)]
		[Description("Occurs after an item thumbnail is cached.")]
		public event ThumbnailCachedEventHandler ThumbnailCached;

		[Category("Behavior")]
		[Browsable(true)]
		[Description("Occurs before an item thumbnail is cached.")]
		public event ThumbnailCachingEventHandler ThumbnailCaching;

		[Category("Behavior")]
		[Browsable(true)]
		[Description("Occurs when thumbnail image for a virtual item is requested.")]
		public event RetrieveVirtualItemThumbnailEventHandler RetrieveVirtualItemThumbnail;

		[Category("Behavior")]
		[Browsable(true)]
		[Description("Occurs when source image for a virtual item is requested.")]
		public event RetrieveVirtualItemImageEventHandler RetrieveVirtualItemImage;

		[Category("Behavior")]
		[Browsable(true)]
		[Description("Occurs when details of a virtual item are requested.")]
		public event RetrieveVirtualItemDetailsEventHandler RetrieveVirtualItemDetails;

		internal const int DefaultColumnWidth = 100;

		internal const int SeparatorSize = 12;

		internal const int PaneBorderSize = 4;

		private const int WS_BORDER = 8388608;

		private const int WS_EX_CLIENTEDGE = 512;

		private BorderStyle mBorderStyle;

		private CacheMode mCacheMode;

		private int mCacheLimitAsItemCount;

		private long mCacheLimitAsMemory;

		private ImageListView.ImageListViewColumnHeaderCollection mColumns;

		private Image mDefaultImage;

		private Image mErrorImage;

		private Font mHeaderFont;

		private ImageListView.ImageListViewItemCollection mItems;

		private int mPaneWidth;

		internal ImageListView.ImageListViewRenderer mRenderer;

		private bool mRetryOnError;

		internal ImageListView.ImageListViewSelectedItemCollection mSelectedItems;

		private ColumnType mSortColumn;

		private SortOrder mSortOrder;

		private Size mThumbnailSize;

		private UseEmbeddedThumbnails mUseEmbeddedThumbnails;

		private Autodesk.Revit.DB.View mView;

		private System.Drawing.Point mViewOffset;

		internal HScrollBar hScrollBar;

		internal VScrollBar vScrollBar;

		internal ImageListViewLayoutManager layoutManager;

		private bool disposed;

		private bool forceRefresh;

		internal ImageListView.ImageListViewNavigationManager navigationManager;

		internal ImageListViewCacheManager cacheManager;

		internal ImageListViewItemCacheManager itemCacheManager;

		public class HitInfo
		{
			public bool ItemHit
			{
				get
				{
					return this.ItemIndex != -1;
				}
			}

			public bool ColumnHit
			{
				get
				{
					return this.ColumnIndex != (ColumnType)(-1);
				}
			}

			public bool ColumnSeparatorHit
			{
				get
				{
					return this.ColumnSeparator != (ColumnType)(-1);
				}
			}

			public int ItemIndex { get; private set; }

			public ColumnType ColumnIndex { get; private set; }

			public ColumnType ColumnSeparator { get; private set; }

			public bool PaneBorder { get; private set; }

			public bool InItemArea { get; private set; }

			public bool InHeaderArea { get; private set; }

			public bool InPaneArea { get; private set; }

			private HitInfo(int itemIndex, ColumnType columnIndex, ColumnType columnSeparator, bool paneBorder, bool inItemArea, bool inHeaderArea, bool inPaneArea)
			{
				this.ItemIndex = itemIndex;
				this.ColumnIndex = columnIndex;
				this.ColumnSeparator = columnSeparator;
				this.InItemArea = inItemArea;
				this.InHeaderArea = inHeaderArea;
				this.InPaneArea = inPaneArea;
				this.PaneBorder = paneBorder;
			}

			internal HitInfo(int itemIndex) : this(itemIndex, (ColumnType)(-1), (ColumnType)(-1), false, true, false, false)
			{
			}

			internal HitInfo(ColumnType columnIndex, ColumnType columnSeparator) : this(-1, columnIndex, columnSeparator, false, false, true, false)
			{
			}

			internal HitInfo(bool paneBorder) : this(-1, (ColumnType)(-1), (ColumnType)(-1), paneBorder, false, false, true)
			{
			}
		}

		public class ImageListViewColumnHeader
		{
			[Category("Appearance")]
			[Browsable(false)]
			[Description("Gets the default header text for this column type.")]
			[Localizable(true)]
			public virtual string DefaultText
			{
				get
				{
					return this.owner.GetDefaultText(this.mType);
				}
			}

			[Category("Appearance")]
			[Browsable(true)]
			[Description("Gets the bounds of the item in client coordinates.")]
			public int DisplayIndex
			{
				get
				{
					return this.mDisplayIndex;
				}
				set
				{
					int num = this.mDisplayIndex;
					if (value < 0 || value > this.owner.Count - 1)
					{
						throw new IndexOutOfRangeException();
					}
					if (num == -1)
					{
						this.mDisplayIndex = value;
						return;
					}
					ImageListView.ImageListViewColumnHeader imageListViewColumnHeader = null;
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader2 in this.owner)
					{
						if (imageListViewColumnHeader2.DisplayIndex == value)
						{
							imageListViewColumnHeader = imageListViewColumnHeader2;
							break;
						}
					}
					if (imageListViewColumnHeader != null)
					{
						this.mDisplayIndex = value;
						imageListViewColumnHeader.mDisplayIndex = num;
						if (this.mImageListView != null)
						{
							this.mImageListView.Refresh();
						}
					}
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets the ImageListView owning this item.")]
			public ImageListView ImageListView
			{
				get
				{
					return this.mImageListView;
				}
			}

			[Category("Appearance")]
			[Browsable(true)]
			[Description("Gets or sets the column header text.")]
			public string Text
			{
				get
				{
					if (!string.IsNullOrEmpty(this.mText))
					{
						return this.mText;
					}
					return this.DefaultText;
				}
				set
				{
					this.mText = value;
					if (this.mImageListView != null)
					{
						this.mImageListView.Refresh();
					}
				}
			}

			[Category("Appearance")]
			[Browsable(false)]
			[Description("Gets or sets the type of information displayed by the column.")]
			public ColumnType Type
			{
				get
				{
					return this.mType;
				}
			}

			[Category("Appearance")]
			[Browsable(true)]
			[Description("Gets or sets a value indicating whether the control is displayed.")]
			[DefaultValue(true)]
			public bool Visible
			{
				get
				{
					return this.mVisible;
				}
				set
				{
					this.mVisible = value;
					if (this.mImageListView != null)
					{
						this.mImageListView.Refresh();
					}
				}
			}

			[Category("Appearance")]
			[Browsable(true)]
			[Description("Gets or sets the column width.")]
			[DefaultValue(100)]
			public int Width
			{
				get
				{
					return this.mWidth;
				}
				set
				{
					this.mWidth = Math.Max(12, value);
					if (this.mImageListView != null)
					{
						this.mImageListView.Refresh();
					}
				}
			}

			public ImageListViewColumnHeader(ColumnType type, string text, int width)
			{
				this.mImageListView = null;
				this.owner = null;
				this.mText = text;
				this.mType = type;
				this.mWidth = width;
				this.mVisible = true;
				this.mDisplayIndex = -1;
			}

			public ImageListViewColumnHeader(ColumnType type, string text) : this(type, text, 100)
			{
			}

			public ImageListViewColumnHeader(ColumnType type, int width) : this(type, "", width)
			{
			}

			public ImageListViewColumnHeader(ColumnType type) : this(type, "", 100)
			{
			}

			public ImageListViewColumnHeader() : this(ColumnType.Name)
			{
			}

			public void AutoFit()
			{
				if (this.mImageListView == null)
				{
					throw new Autodesk.Revit.Exceptions.InvalidOperationException("Cannot calculate column width. Owner image list view is null.");
				}
				int num = 0;
				foreach (ImageListViewItem imageListViewItem in this.mImageListView.Items)
				{
					int width = TextRenderer.MeasureText(imageListViewItem.GetSubItemText(this.Type), this.mImageListView.Font).Width;
					num = Math.Max(num, width);
				}
				this.Width = num + 8;
				this.mImageListView.Refresh();
			}

			private int mDisplayIndex;

			internal ImageListView mImageListView;

			private string mText;

			private ColumnType mType;

			private bool mVisible;

			private int mWidth;

			internal ImageListView.ImageListViewColumnHeaderCollection owner;
		}

		[Editor(typeof(ColumnHeaderCollectionEditor), typeof(UITypeEditor))]
		[TypeConverter(typeof(ColumnHeaderCollectionTypeConverter))]
		public class ImageListViewColumnHeaderCollection : IEnumerable<ImageListView.ImageListViewColumnHeader>, IEnumerable
		{
			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets the number of columns in the collection.")]
			public int Count
			{
				get
				{
					return this.mItems.Length;
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets the ImageListView owning this collection.")]
			public ImageListView ImageListView
			{
				get
				{
					return this.mImageListView;
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets or item at the specified index within the collection.")]
			public ImageListView.ImageListViewColumnHeader this[int index]
			{
				get
				{
					return this.mItems[index];
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets or sets the item with the specified type within the collection.")]
			public ImageListView.ImageListViewColumnHeader this[ColumnType type]
			{
				get
				{
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in this)
					{
						if (imageListViewColumnHeader.Type == type)
						{
							return imageListViewColumnHeader;
						}
					}
					throw new ArgumentException("Unknown column type.", "type");
				}
			}

			internal ImageListViewColumnHeaderCollection(ImageListView owner)
			{
				this.mImageListView = owner;
				this.mItems = new ImageListView.ImageListViewColumnHeader[]
				{
					new ImageListView.ImageListViewColumnHeader(ColumnType.Name),
					new ImageListView.ImageListViewColumnHeader(ColumnType.FileSize),
					new ImageListView.ImageListViewColumnHeader(ColumnType.DateModified),
					new ImageListView.ImageListViewColumnHeader(ColumnType.Dimensions),
					new ImageListView.ImageListViewColumnHeader(ColumnType.Resolution),
					new ImageListView.ImageListViewColumnHeader(ColumnType.FilePath),
					new ImageListView.ImageListViewColumnHeader(ColumnType.FileType),
					new ImageListView.ImageListViewColumnHeader(ColumnType.FileName),
					new ImageListView.ImageListViewColumnHeader(ColumnType.DateCreated),
					new ImageListView.ImageListViewColumnHeader(ColumnType.DateAccessed),
					new ImageListView.ImageListViewColumnHeader(ColumnType.ImageDescription),
					new ImageListView.ImageListViewColumnHeader(ColumnType.EquipmentModel),
					new ImageListView.ImageListViewColumnHeader(ColumnType.DateTaken),
					new ImageListView.ImageListViewColumnHeader(ColumnType.Artist),
					new ImageListView.ImageListViewColumnHeader(ColumnType.Copyright),
					new ImageListView.ImageListViewColumnHeader(ColumnType.ExposureTime),
					new ImageListView.ImageListViewColumnHeader(ColumnType.FNumber),
					new ImageListView.ImageListViewColumnHeader(ColumnType.ISOSpeed),
					new ImageListView.ImageListViewColumnHeader(ColumnType.ShutterSpeed),
					new ImageListView.ImageListViewColumnHeader(ColumnType.Aperture),
					new ImageListView.ImageListViewColumnHeader(ColumnType.UserComment)
				};
				for (int i = 0; i < this.mItems.Length; i++)
				{
					ImageListView.ImageListViewColumnHeader imageListViewColumnHeader = this.mItems[i];
					imageListViewColumnHeader.mImageListView = this.mImageListView;
					imageListViewColumnHeader.owner = this;
					imageListViewColumnHeader.DisplayIndex = i;
					if (i >= 4)
					{
						imageListViewColumnHeader.Visible = false;
					}
				}
			}

			[Localizable(true)]
			public string GetDefaultText(ColumnType type)
			{
				return new ResourceManager("Manina.Windows.Forms.ImageListViewResources", Assembly.GetExecutingAssembly()).GetString(type.ToString());
			}

			public IEnumerator<ImageListView.ImageListViewColumnHeader> GetEnumerator()
			{
				foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in this.mItems)
				{
					yield return imageListViewColumnHeader;
				}
				ImageListView.ImageListViewColumnHeader[] array = null;
				yield break;
				yield break;
			}

			public List<ImageListView.ImageListViewColumnHeader> GetDisplayedColumns()
			{
				List<ImageListView.ImageListViewColumnHeader> list = new List<ImageListView.ImageListViewColumnHeader>();
				foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in this.mItems)
				{
					if (imageListViewColumnHeader.Visible)
					{
						list.Add(imageListViewColumnHeader);
					}
				}
				list.Sort(new Comparison<ImageListView.ImageListViewColumnHeader>(ImageListView.ImageListViewColumnHeaderCollection.ColumnCompare));
				return list;
			}

			internal static int ColumnCompare(ImageListView.ImageListViewColumnHeader a, ImageListView.ImageListViewColumnHeader b)
			{
				if (a.DisplayIndex < b.DisplayIndex)
				{
					return -1;
				}
				if (a.DisplayIndex > b.DisplayIndex)
				{
					return 1;
				}
				return 0;
			}

			IEnumerator IEnumerable.GetEnumerator()
			{
				return this.GetEnumerator();
			}

			private ImageListView mImageListView;

			private ImageListView.ImageListViewColumnHeader[] mItems;
		}

		public class ImageListViewItemCollection : IList<ImageListViewItem>, ICollection<ImageListViewItem>, IEnumerable<ImageListViewItem>, IEnumerable, ICollection, IList
		{
			internal ImageListViewItemCollection(ImageListView owner)
			{
				this.mItems = new List<ImageListViewItem>();
				this.mFocused = null;
				this.mImageListView = owner;
			}

			public int Count
			{
				get
				{
					return this.mItems.Count;
				}
			}

			public bool IsReadOnly
			{
				get
				{
					return false;
				}
			}

			public ImageListViewItem FocusedItem
			{
				get
				{
					return this.mFocused;
				}
				set
				{
					ImageListViewItem imageListViewItem = this.mFocused;
					this.mFocused = value;
					if (imageListViewItem != this.mFocused && this.mImageListView != null)
					{
						this.mImageListView.Refresh();
					}
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets the ImageListView owning this collection.")]
			public ImageListView ImageListView
			{
				get
				{
					return this.mImageListView;
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets or sets the item at the specified index.")]
			public ImageListViewItem this[int index]
			{
				get
				{
					return this.mItems[index];
				}
				set
				{
					if (this.mItems[index] == this.mFocused)
					{
						this.mFocused = value;
					}
					bool selected = this.mItems[index].Selected;
					value.mIndex = index;
					if (this.mImageListView != null)
					{
						value.mImageListView = this.mImageListView;
					}
					value.owner = this;
					this.mItems[index] = value;
					if (this.mImageListView != null)
					{
						if (this.mImageListView.CacheMode == CacheMode.Continuous)
						{
							if (value.isVirtualItem)
							{
								this.mImageListView.cacheManager.Add(value.Guid, value.VirtualItemKey, this.mImageListView.ThumbnailSize, this.mImageListView.UseEmbeddedThumbnails);
							}
							else
							{
								this.mImageListView.cacheManager.Add(value.Guid, value.FileName, this.mImageListView.ThumbnailSize, this.mImageListView.UseEmbeddedThumbnails);
							}
						}
						this.mImageListView.itemCacheManager.Add(value);
						if (value.Selected != selected)
						{
							this.mImageListView.OnSelectionChangedInternal();
						}
					}
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets or sets the item with the specified Guid.")]
			internal ImageListViewItem this[Guid guid]
			{
				get
				{
					foreach (ImageListViewItem imageListViewItem in this)
					{
						if (imageListViewItem.Guid == guid)
						{
							return imageListViewItem;
						}
					}
					throw new ArgumentException("No item with this guid exists.", "guid");
				}
			}

			public void Add(ImageListViewItem item)
			{
				this.AddInternal(item);
				if (this.mImageListView != null)
				{
					if (item.Selected)
					{
						this.mImageListView.OnSelectionChangedInternal();
					}
					this.mImageListView.Refresh();
				}
			}

			public void Add(string filename)
			{
				this.Add(new ImageListViewItem(filename));
			}

			public void Add(object key, string text)
			{
				this.Add(key, text, null);
			}

			public void Add(object key, string text, Image initialThumbnail)
			{
				ImageListViewItem imageListViewItem = new ImageListViewItem(key, text);
				if (this.mImageListView != null && initialThumbnail != null)
				{
					this.mImageListView.cacheManager.Add(imageListViewItem.Guid, key, this.mImageListView.ThumbnailSize, initialThumbnail, this.mImageListView.UseEmbeddedThumbnails);
				}
				this.Add(imageListViewItem);
			}

			public void AddRange(ImageListViewItem[] items)
			{
				if (this.mImageListView != null)
				{
					this.mImageListView.mRenderer.SuspendPaint();
				}
				foreach (ImageListViewItem item in items)
				{
					this.Add(item);
				}
				if (this.mImageListView != null)
				{
					this.mImageListView.Refresh();
					this.mImageListView.mRenderer.ResumePaint();
				}
			}

			public void AddRange(string[] filenames)
			{
				if (this.mImageListView != null)
				{
					this.mImageListView.mRenderer.SuspendPaint();
				}
				for (int i = 0; i < filenames.Length; i++)
				{
					this.Add(filenames[i]);
				}
				if (this.mImageListView != null)
				{
					this.mImageListView.Refresh();
					this.mImageListView.mRenderer.ResumePaint();
				}
			}

			public void Clear()
			{
				if (this.mImageListView != null)
				{
					this.mImageListView.cacheManager.Clear();
					this.mImageListView.SelectedItems.Clear();
					this.mImageListView.Refresh();
				}
				this.mItems.Clear();
				this.mFocused = null;
			}

			public bool Contains(ImageListViewItem item)
			{
				return this.mItems.Contains(item);
			}

			public IEnumerator<ImageListViewItem> GetEnumerator()
			{
				return this.mItems.GetEnumerator();
			}

			public void Insert(int index, ImageListViewItem item)
			{
				this.InsertInternal(index, item);
				if (this.mImageListView != null)
				{
					if (item.Selected)
					{
						this.mImageListView.OnSelectionChangedInternal();
					}
					this.mImageListView.Refresh();
				}
			}

			public bool Remove(ImageListViewItem item)
			{
				for (int i = item.mIndex; i < this.mItems.Count; i++)
				{
					this.mItems[i].mIndex--;
				}
				if (item == this.mFocused)
				{
					this.mFocused = null;
				}
				bool result = this.mItems.Remove(item);
				if (this.mImageListView != null)
				{
					this.mImageListView.cacheManager.Remove(item.Guid);
					if (item.Selected)
					{
						this.mImageListView.OnSelectionChangedInternal();
					}
					this.mImageListView.Refresh();
				}
				return result;
			}

			public void RemoveAt(int index)
			{
				this.Remove(this.mItems[index]);
			}

			internal void AddInternal(ImageListViewItem item)
			{
				if (this.mImageListView != null && !item.isVirtualItem && !this.mImageListView.AllowDuplicateFileNames && this.mItems.Exists((ImageListViewItem a) => string.Compare(a.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
				{
					return;
				}
				item.owner = this;
				item.mIndex = this.mItems.Count;
				this.mItems.Add(item);
				if (this.mImageListView != null)
				{
					item.mImageListView = this.mImageListView;
					if (this.mImageListView.CacheMode == CacheMode.Continuous)
					{
						if (item.isVirtualItem)
						{
							this.mImageListView.cacheManager.Add(item.Guid, item.VirtualItemKey, this.mImageListView.ThumbnailSize, this.mImageListView.UseEmbeddedThumbnails);
						}
						else
						{
							this.mImageListView.cacheManager.Add(item.Guid, item.FileName, this.mImageListView.ThumbnailSize, this.mImageListView.UseEmbeddedThumbnails);
						}
					}
					this.mImageListView.itemCacheManager.Add(item);
				}
			}

			internal void InsertInternal(int index, ImageListViewItem item)
			{
				if (this.mImageListView != null && !this.mImageListView.AllowDuplicateFileNames && this.mItems.Exists((ImageListViewItem a) => string.Compare(a.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
				{
					return;
				}
				item.owner = this;
				item.mIndex = index;
				for (int i = index; i < this.mItems.Count; i++)
				{
					this.mItems[i].mIndex++;
				}
				this.mItems.Insert(index, item);
				if (this.mImageListView != null)
				{
					item.mImageListView = this.mImageListView;
					if (this.mImageListView.CacheMode == CacheMode.Continuous)
					{
						if (item.isVirtualItem)
						{
							this.mImageListView.cacheManager.Add(item.Guid, item.VirtualItemKey, this.mImageListView.ThumbnailSize, this.mImageListView.UseEmbeddedThumbnails);
						}
						else
						{
							this.mImageListView.cacheManager.Add(item.Guid, item.FileName, this.mImageListView.ThumbnailSize, this.mImageListView.UseEmbeddedThumbnails);
						}
					}
					this.mImageListView.itemCacheManager.Add(item);
				}
			}

			internal void RemoveInternal(ImageListViewItem item)
			{
				this.RemoveInternal(item, true);
			}

			internal void RemoveInternal(ImageListViewItem item, bool removeFromCache)
			{
				for (int i = item.mIndex; i < this.mItems.Count; i++)
				{
					this.mItems[i].mIndex--;
				}
				if (item == this.mFocused)
				{
					this.mFocused = null;
				}
				if (removeFromCache && this.mImageListView != null)
				{
					this.mImageListView.cacheManager.Remove(item.Guid);
				}
				this.mItems.Remove(item);
			}

			internal int IndexOf(ImageListViewItem item)
			{
				return item.Index;
			}

			internal int IndexOf(Guid guid)
			{
				for (int i = 0; i < this.mItems.Count; i++)
				{
					if (this.mItems[i].Guid == guid)
					{
						return i;
					}
				}
				return -1;
			}

			internal void Sort()
			{
				if (this.mImageListView == null || this.mImageListView.SortOrder == SortOrder.None)
				{
					return;
				}
				Cursor cursor = this.mImageListView.Cursor;
				this.mImageListView.Cursor = Cursors.WaitCursor;
				this.mItems.Sort(new ImageListView.ImageListViewItemCollection.ImageListViewItemComparer(this.mImageListView.SortColumn, this.mImageListView.SortOrder));
				for (int i = 0; i < this.mItems.Count; i++)
				{
					this.mItems[i].mIndex = i;
				}
				this.mImageListView.Cursor = cursor;
			}

			void ICollection<ImageListViewItem>.CopyTo(ImageListViewItem[] array, int arrayIndex)
			{
				this.mItems.CopyTo(array, arrayIndex);
			}

			[Obsolete("Use ImageListViewItem.Index property instead.")]
			int IList<ImageListViewItem>.IndexOf(ImageListViewItem item)
			{
				return this.mItems.IndexOf(item);
			}

			void ICollection.CopyTo(Array array, int index)
			{
				if (!(array is ImageListViewItem[]))
				{
					throw new ArgumentException("An array of ImageListViewItem is required.", "array");
				}
				this.mItems.CopyTo((ImageListViewItem[])array, index);
			}

			int ICollection.Count
			{
				get
				{
					return this.mItems.Count;
				}
			}

			bool ICollection.IsSynchronized
			{
				get
				{
					return false;
				}
			}

			object ICollection.SyncRoot
			{
				get
				{
					throw new NotSupportedException();
				}
			}

			int IList.Add(object value)
			{
				if (!(value is ImageListViewItem))
				{
					throw new ArgumentException("An object of type ImageListViewItem is required.", "value");
				}
				ImageListViewItem item = (ImageListViewItem)value;
				this.Add(item);
				return this.mItems.IndexOf(item);
			}

			bool IList.Contains(object value)
			{
				if (!(value is ImageListViewItem))
				{
					throw new ArgumentException("An object of type ImageListViewItem is required.", "value");
				}
				return this.mItems.Contains((ImageListViewItem)value);
			}

			IEnumerator IEnumerable.GetEnumerator()
			{
				return this.mItems.GetEnumerator();
			}

			int IList.IndexOf(object value)
			{
				if (!(value is ImageListViewItem))
				{
					throw new ArgumentException("An object of type ImageListViewItem is required.", "value");
				}
				return this.IndexOf((ImageListViewItem)value);
			}

			void IList.Insert(int index, object value)
			{
				if (!(value is ImageListViewItem))
				{
					throw new ArgumentException("An object of type ImageListViewItem is required.", "value");
				}
				this.Insert(index, (ImageListViewItem)value);
			}

			bool IList.IsFixedSize
			{
				get
				{
					return false;
				}
			}

			void IList.Remove(object value)
			{
				if (!(value is ImageListViewItem))
				{
					throw new ArgumentException("An object of type ImageListViewItem is required.", "value");
				}
				this.Remove((ImageListViewItem)value);
			}

			object IList.this[int index]
			{
				get
				{
					return this[index];
				}
				set
				{
					if (!(value is ImageListViewItem))
					{
						throw new ArgumentException("An object of type ImageListViewItem is required.", "value");
					}
					this[index] = (ImageListViewItem)value;
				}
			}

			private List<ImageListViewItem> mItems;

			internal ImageListView mImageListView;

			private ImageListViewItem mFocused;

			private class ImageListViewItemComparer : IComparer<ImageListViewItem>
			{
				public ImageListViewItemComparer(ColumnType sortColumn, SortOrder order)
				{
					this.mSortColumn = sortColumn;
					this.mOrder = order;
				}

				public int Compare(ImageListViewItem x, ImageListViewItem y)
				{
					int num = (this.mOrder == SortOrder.Ascending) ? 1 : -1;
					int num2;
					switch (this.mSortColumn)
					{
					case ColumnType.Name:
						num2 = string.Compare(x.Text, y.Text, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.DateAccessed:
						num2 = DateTime.Compare(x.DateAccessed, y.DateAccessed);
						break;
					case ColumnType.DateCreated:
						num2 = DateTime.Compare(x.DateCreated, y.DateCreated);
						break;
					case ColumnType.DateModified:
						num2 = DateTime.Compare(x.DateModified, y.DateModified);
						break;
					case ColumnType.FileType:
						num2 = string.Compare(x.FileType, y.FileType, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.FileName:
						num2 = string.Compare(x.FileName, y.FileName, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.FilePath:
						num2 = string.Compare(x.FilePath, y.FilePath, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.FileSize:
						num2 = ((x.FileSize < y.FileSize) ? -1 : ((x.FileSize > y.FileSize) ? 1 : 0));
						break;
					case ColumnType.Dimensions:
					{
						long num3 = (long)(x.Dimensions.Width * x.Dimensions.Height);
						long num4 = (long)(y.Dimensions.Width * y.Dimensions.Height);
						num2 = ((num3 < num4) ? -1 : ((num3 > num4) ? 1 : 0));
						break;
					}
					case ColumnType.Resolution:
					{
						float num5 = x.Resolution.Width * x.Resolution.Height;
						float num6 = y.Resolution.Width * y.Resolution.Height;
						num2 = ((num5 < num6) ? -1 : ((num5 > num6) ? 1 : 0));
						break;
					}
					case ColumnType.ImageDescription:
						num2 = string.Compare(x.ImageDescription, y.ImageDescription, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.EquipmentModel:
						num2 = string.Compare(x.EquipmentModel, y.EquipmentModel, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.DateTaken:
						num2 = DateTime.Compare(x.DateTaken, y.DateTaken);
						break;
					case ColumnType.Artist:
						num2 = string.Compare(x.Artist, y.Artist, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.Copyright:
						num2 = string.Compare(x.Copyright, y.Copyright, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.ExposureTime:
						num2 = string.Compare(x.ExposureTime, y.ExposureTime, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.FNumber:
						num2 = ((x.FNumber < y.FNumber) ? -1 : ((x.FNumber > y.FNumber) ? 1 : 0));
						break;
					case ColumnType.ISOSpeed:
						num2 = ((x.ISOSpeed < y.ISOSpeed) ? -1 : ((x.ISOSpeed > y.ISOSpeed) ? 1 : 0));
						break;
					case ColumnType.ShutterSpeed:
						num2 = string.Compare(x.ShutterSpeed, y.ShutterSpeed, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.Aperture:
						num2 = string.Compare(x.Aperture, y.Aperture, StringComparison.InvariantCultureIgnoreCase);
						break;
					case ColumnType.UserComment:
						num2 = string.Compare(x.UserComment, y.UserComment, StringComparison.InvariantCultureIgnoreCase);
						break;
					default:
						num2 = 0;
						break;
					}
					return num * num2;
				}

				private ColumnType mSortColumn;

				private SortOrder mOrder;
			}
		}

		internal class ImageListViewNavigationManager : IDisposable
		{
			public bool LeftButton { get; private set; }

			public bool RightButton { get; private set; }

			public bool ShiftKey { get; private set; }

			public bool ControlKey { get; private set; }

			public ImageListViewItem HoveredItem { get; private set; }

			public ImageListView.ImageListViewColumnHeader HoveredColumn { get; private set; }

			public ImageListView.ImageListViewColumnHeader HoveredSeparator { get; private set; }

			public ImageListView.ImageListViewColumnHeader SelectedSeperator { get; private set; }

			public bool HoveredPaneBorder { get; private set; }

			public bool MouseSelecting { get; private set; }

			public bool DraggingSeperator { get; private set; }

			public bool ResizingPane { get; private set; }

			public ImageListViewItem DropTarget { get; private set; }

			public bool DropToRight { get; private set; }

			public System.Drawing.Rectangle SelectionRectangle { get; private set; }

			public ImageListViewNavigationManager(ImageListView owner)
			{
				this.mImageListView = owner;
				this.DraggingSeperator = false;
				this.ResizingPane = false;
				this.LeftButton = false;
				this.RightButton = false;
				this.ShiftKey = false;
				this.ControlKey = false;
				this.HoveredItem = null;
				this.HoveredColumn = null;
				this.HoveredSeparator = null;
				this.SelectedSeperator = null;
				this.HoveredPaneBorder = false;
				this.MouseSelecting = false;
				this.DropTarget = null;
				this.DropToRight = false;
				this.selfDragging = false;
				this.highlightedItems = new Dictionary<ImageListViewItem, bool>();
				this.scrollTimer = new Timer();
				this.scrollTimer.Interval = 100;
				this.scrollTimer.Enabled = false;
				this.scrollTimer.Tick += this.scrollTimer_Tick;
				this.suppressClick = false;
			}

			public ItemHighlightState HighlightState(ImageListViewItem item)
			{
				bool flag = false;
				if (!this.highlightedItems.TryGetValue(item, out flag))
				{
					return ItemHighlightState.NotHighlighted;
				}
				if (flag)
				{
					return ItemHighlightState.HighlightedAndSelected;
				}
				return ItemHighlightState.HighlightedAndUnSelected;
			}

			public void Dispose()
			{
				this.scrollTimer.Dispose();
			}

			public void MouseDown(MouseEventArgs e)
			{
				if ((e.Button & MouseButtons.Left) != MouseButtons.None)
				{
					this.LeftButton = true;
				}
				if ((e.Button & MouseButtons.Right) != MouseButtons.None)
				{
					this.RightButton = true;
				}
				this.DoHitTest(e.Location);
				this.lastMouseDownInItemArea = this.inItemArea;
				this.lastMouseDownInColumnHeaderArea = this.inHeaderArea;
				this.lastMouseDownInPaneArea = this.inPaneArea;
				this.lastMouseDownOverItem = (this.HoveredItem != null);
				this.lastMouseDownOverColumn = (this.HoveredColumn != null);
				this.lastMouseDownOverSeparator = (this.HoveredSeparator != null);
				this.lastMouseDownOverPaneBorder = this.HoveredPaneBorder;
				this.lastViewOffset = this.mImageListView.ViewOffset;
				this.lastMouseDownLocation = e.Location;
			}

			public void MouseMove(MouseEventArgs e)
			{
				ImageListViewItem hoveredItem = this.HoveredItem;
				ImageListView.ImageListViewColumnHeader hoveredColumn = this.HoveredColumn;
				ImageListView.ImageListViewColumnHeader hoveredSeparator = this.HoveredSeparator;
				this.DoHitTest(e.Location);
				this.mImageListView.mRenderer.SuspendPaint();
				if (this.MouseSelecting && this.mImageListView.ScrollOrientation == ScrollOrientation.VerticalScroll && !this.scrollTimer.Enabled)
				{
					if (e.Y > this.mImageListView.ClientRectangle.Bottom)
					{
						this.scrollTimer.Tag = -120;
						this.scrollTimer.Enabled = true;
					}
					else if (e.Y < this.mImageListView.ClientRectangle.Top)
					{
						this.scrollTimer.Tag = 120;
						this.scrollTimer.Enabled = true;
					}
				}
				else if (this.MouseSelecting && this.mImageListView.ScrollOrientation == ScrollOrientation.HorizontalScroll && !this.scrollTimer.Enabled)
				{
					if (e.X > this.mImageListView.ClientRectangle.Right)
					{
						this.scrollTimer.Tag = -120;
						this.scrollTimer.Enabled = true;
					}
					else if (e.X < this.mImageListView.ClientRectangle.Left)
					{
						this.scrollTimer.Tag = 120;
						this.scrollTimer.Enabled = true;
					}
				}
				else if (this.scrollTimer.Enabled && this.mImageListView.ClientRectangle.Contains(e.Location))
				{
					this.scrollTimer.Enabled = false;
				}
				if (this.DraggingSeperator)
				{
					int num = e.Location.X - this.lastSeparatorDragLocation.X;
					int num2 = this.SelectedSeperator.Width + num;
					if (num2 > 16)
					{
						this.lastSeparatorDragLocation = e.Location;
					}
					else
					{
						this.lastSeparatorDragLocation = new System.Drawing.Point(e.Location.X - num2 + 16, e.Location.Y);
						num2 = 16;
					}
					this.SelectedSeperator.Width = num2;
					this.HoveredItem = null;
					this.HoveredColumn = this.SelectedSeperator;
					this.HoveredSeparator = this.SelectedSeperator;
					this.mImageListView.Refresh();
				}
				else if (this.ResizingPane)
				{
					int num3 = e.Location.X - this.lastPaneResizeLocation.X;
					int num4 = this.mImageListView.mPaneWidth + num3;
					if (num4 > 2)
					{
						this.lastPaneResizeLocation = e.Location;
					}
					else
					{
						this.lastPaneResizeLocation = new System.Drawing.Point(e.Location.X - num4 + 2, e.Location.Y);
						num4 = 2;
					}
					this.mImageListView.mPaneWidth = num4;
					this.HoveredItem = null;
					this.HoveredColumn = null;
					this.HoveredSeparator = null;
					this.mImageListView.Refresh();
				}
				else if (!this.MouseSelecting)
				{
					if (!this.MouseSelecting && !this.DraggingSeperator && !this.ResizingPane && this.inItemArea && this.lastMouseDownInItemArea && (this.LeftButton || this.RightButton) && (Math.Abs(e.Location.X - this.lastMouseDownLocation.X) > 5 || Math.Abs(e.Location.Y - this.lastMouseDownLocation.Y) > 5))
					{
						if (!this.lastMouseDownOverItem && this.HoveredItem == null)
						{
							this.MouseSelecting = true;
							this.SelectionRectangle = new System.Drawing.Rectangle(this.lastMouseDownLocation, new Size(0, 0));
							this.mImageListView.Refresh();
						}
						else if (this.lastMouseDownOverItem && this.HoveredItem != null && this.mImageListView.AllowDrag)
						{
							if (!this.HoveredItem.Selected)
							{
								this.mImageListView.SelectedItems.Clear(false);
								this.HoveredItem.mSelected = true;
								this.mImageListView.OnSelectionChangedInternal();
								this.DropTarget = null;
								this.mImageListView.Refresh(true);
							}
							List<string> list = new List<string>();
							foreach (ImageListViewItem imageListViewItem in this.mImageListView.SelectedItems)
							{
								if (imageListViewItem.isVirtualItem)
								{
									VirtualItemImageEventArgs virtualItemImageEventArgs = new VirtualItemImageEventArgs(imageListViewItem.mVirtualItemKey);
									this.mImageListView.RetrieveVirtualItemImageInternal(virtualItemImageEventArgs);
									if (!string.IsNullOrEmpty(virtualItemImageEventArgs.FileName))
									{
										list.Add(virtualItemImageEventArgs.FileName);
									}
								}
								else
								{
									list.Add(imageListViewItem.FileName);
								}
							}
							DataObject data = new DataObject(DataFormats.FileDrop, list.ToArray());
							this.DropTarget = null;
							this.selfDragging = true;
							this.mImageListView.DoDragDrop(data, DragDropEffects.Copy);
							this.selfDragging = false;
							if ((System.Windows.Forms.Control.MouseButtons & MouseButtons.Left) == MouseButtons.None)
							{
								this.LeftButton = false;
							}
							if ((System.Windows.Forms.Control.MouseButtons & MouseButtons.Right) == MouseButtons.None)
							{
								this.RightButton = false;
							}
						}
					}
					else if (!this.MouseSelecting && !this.DraggingSeperator && !this.ResizingPane && this.inHeaderArea && this.lastMouseDownInColumnHeaderArea && this.lastMouseDownOverSeparator && this.LeftButton && this.mImageListView.AllowColumnResize && this.HoveredSeparator != null)
					{
						this.DraggingSeperator = true;
						this.SelectedSeperator = this.HoveredSeparator;
						this.lastSeparatorDragLocation = e.Location;
					}
					else if (!this.MouseSelecting && !this.DraggingSeperator && !this.ResizingPane && this.inPaneArea && this.lastMouseDownInPaneArea && this.lastMouseDownOverPaneBorder && this.LeftButton && this.mImageListView.AllowPaneResize && this.HoveredPaneBorder)
					{
						this.ResizingPane = true;
						this.lastPaneResizeLocation = e.Location;
					}
					else if (this.HoveredItem != hoveredItem || this.HoveredColumn != hoveredColumn || this.HoveredSeparator != hoveredSeparator)
					{
						if (this.HoveredItem != hoveredItem)
						{
							this.mImageListView.OnItemHover(new ItemHoverEventArgs(this.HoveredItem, hoveredItem));
						}
						if (this.HoveredColumn != hoveredColumn)
						{
							this.mImageListView.OnColumnHover(new ColumnHoverEventArgs(this.HoveredColumn, hoveredColumn));
						}
						this.mImageListView.Refresh();
					}
				}
				this.mImageListView.mRenderer.ResumePaint();
				if (this.mImageListView.Cursor != Cursors.VSplit && this.mImageListView.Focused && !this.MouseSelecting)
				{
					if ((this.mImageListView.AllowColumnResize && this.HoveredSeparator != null) || (this.mImageListView.AllowPaneResize && this.HoveredPaneBorder))
					{
						this.mImageListView.Cursor = Cursors.VSplit;
					}
				}
				else if (this.mImageListView.Cursor == Cursors.VSplit && (!this.inHeaderArea || (!this.DraggingSeperator && this.HoveredSeparator == null)) && (!this.inPaneArea || (!this.ResizingPane && !this.HoveredPaneBorder)))
				{
					this.mImageListView.Cursor = Cursors.Default;
				}
				this.lastMouseMoveLocation = e.Location;
			}

			public void MouseUp(MouseEventArgs e)
			{
				this.DoHitTest(e.Location);
				this.mImageListView.mRenderer.SuspendPaint();
				if (this.scrollTimer.Enabled)
				{
					this.scrollTimer.Enabled = false;
				}
				if (this.DraggingSeperator)
				{
					this.mImageListView.OnColumnWidthChanged(new ColumnEventArgs(this.SelectedSeperator));
					this.SelectedSeperator = null;
					this.DraggingSeperator = false;
				}
				else if (this.ResizingPane)
				{
					this.ResizingPane = false;
				}
				else if (this.MouseSelecting)
				{
					if (this.highlightedItems.Count != 0)
					{
						foreach (KeyValuePair<ImageListViewItem, bool> keyValuePair in this.highlightedItems)
						{
							keyValuePair.Key.mSelected = keyValuePair.Value;
						}
						this.highlightedItems.Clear();
					}
					this.mImageListView.OnSelectionChangedInternal();
					this.MouseSelecting = false;
					this.mImageListView.Refresh();
				}
				else if (this.lastMouseDownInItemArea && this.lastMouseDownOverItem && this.HoveredItem != null && this.LeftButton)
				{
					this.mImageListView.SelectedItems.Clear(false);
					this.HoveredItem.mSelected = true;
					this.mImageListView.OnSelectionChangedInternal();
					this.mImageListView.OnItemClick(new ItemClickEventArgs(this.HoveredItem, e.Location, e.Button));
					this.mImageListView.Items.FocusedItem = this.HoveredItem;
					this.mImageListView.Refresh();
				}
				else if (this.lastMouseDownInItemArea && this.lastMouseDownOverItem && this.HoveredItem != null && this.RightButton)
				{
					if (!this.ControlKey && !this.HoveredItem.Selected)
					{
						this.mImageListView.SelectedItems.Clear(false);
						this.HoveredItem.mSelected = true;
						this.mImageListView.OnSelectionChangedInternal();
					}
					this.mImageListView.OnItemClick(new ItemClickEventArgs(this.HoveredItem, e.Location, e.Button));
					this.mImageListView.Items.FocusedItem = this.HoveredItem;
				}
				else if ((!this.lastMouseDownInItemArea || !this.inItemArea || this.HoveredItem != null || (!this.LeftButton && !this.RightButton)) && this.lastMouseDownInColumnHeaderArea && this.lastMouseDownOverColumn && this.mImageListView.AllowColumnClick && this.HoveredColumn != null && this.HoveredSeparator == null)
				{
					if (!this.suppressClick)
					{
						if (this.mImageListView.SortColumn == this.HoveredColumn.Type)
						{
							if (this.mImageListView.SortOrder == SortOrder.Descending)
							{
								this.mImageListView.SortOrder = SortOrder.Ascending;
							}
							else
							{
								this.mImageListView.SortOrder = SortOrder.Descending;
							}
						}
						else
						{
							this.mImageListView.mSortColumn = this.HoveredColumn.Type;
							this.mImageListView.mSortOrder = SortOrder.Ascending;
							this.mImageListView.Sort();
						}
						this.mImageListView.OnColumnClick(new ColumnClickEventArgs(this.HoveredColumn, e.Location, e.Button));
					}
					else
					{
						this.suppressClick = false;
					}
				}
				if ((e.Button & MouseButtons.Left) != MouseButtons.None)
				{
					this.LeftButton = false;
				}
				if ((e.Button & MouseButtons.Right) != MouseButtons.None)
				{
					this.RightButton = false;
				}
				this.mImageListView.mRenderer.ResumePaint();
			}

			public void MouseDoubleClick(MouseEventArgs e)
			{
				if (this.lastMouseDownInItemArea && this.lastMouseDownOverItem && this.HoveredItem != null)
				{
					this.mImageListView.OnItemDoubleClick(new ItemClickEventArgs(this.HoveredItem, e.Location, e.Button));
					return;
				}
				if (this.lastMouseDownInColumnHeaderArea && this.lastMouseDownOverSeparator && this.mImageListView.AllowColumnClick && this.HoveredSeparator != null)
				{
					this.HoveredSeparator.AutoFit();
					this.mImageListView.Refresh();
					this.suppressClick = true;
				}
			}

			public void MouseLeave()
			{
				if (this.HoveredItem != null || this.HoveredColumn != null || this.HoveredSeparator != null || this.HoveredPaneBorder)
				{
					if (this.HoveredItem != null)
					{
						this.mImageListView.OnItemHover(new ItemHoverEventArgs(null, this.HoveredItem));
					}
					if (this.HoveredColumn != null)
					{
						this.mImageListView.OnColumnHover(new ColumnHoverEventArgs(null, this.HoveredColumn));
					}
					this.HoveredItem = null;
					this.HoveredColumn = null;
					this.HoveredSeparator = null;
					this.HoveredPaneBorder = false;
					this.mImageListView.Refresh();
				}
			}

			public void KeyDown(KeyEventArgs e)
			{
				this.ShiftKey = ((e.Modifiers & Keys.Shift) == Keys.Shift);
				this.ControlKey = ((e.Modifiers & Keys.Control) == Keys.Control);
				this.mImageListView.mRenderer.SuspendPaint();
				if ((this.ShiftKey || this.ControlKey) && this.mImageListView.Items.Count != 0 && this.mImageListView.Items.FocusedItem == null)
				{
					this.mImageListView.Items.FocusedItem = this.mImageListView.Items[0];
					this.mImageListView.Refresh();
				}
				if (this.mImageListView.Items.Count != 0)
				{
					int num = 0;
					if (this.mImageListView.Items.FocusedItem != null)
					{
						num = this.mImageListView.Items.FocusedItem.Index;
					}
					int num2 = this.ApplyNavKey(num, e.KeyCode);
					if (num != num2)
					{
						if (!this.ControlKey)
						{
							if (this.ShiftKey)
							{
								int num3 = 0;
								int num4 = 0;
								if (this.mImageListView.SelectedItems.Count != 0)
								{
									num3 = this.mImageListView.SelectedItems[0].Index;
									num4 = this.mImageListView.SelectedItems[this.mImageListView.SelectedItems.Count - 1].Index;
									this.mImageListView.SelectedItems.Clear(false);
								}
								if (num == num3)
								{
									num3 = num2;
								}
								else if (num == num4)
								{
									num4 = num2;
								}
								for (int i = Math.Min(num3, num4); i <= Math.Max(num3, num4); i++)
								{
									this.mImageListView.Items[i].mSelected = true;
								}
								this.mImageListView.OnSelectionChangedInternal();
							}
							else
							{
								this.mImageListView.SelectedItems.Clear(false);
								this.mImageListView.Items[num2].mSelected = true;
								this.mImageListView.OnSelectionChangedInternal();
							}
						}
						this.mImageListView.Items.FocusedItem = this.mImageListView.Items[num2];
						this.mImageListView.EnsureVisible(num2);
					}
				}
				this.mImageListView.mRenderer.ResumePaint();
			}

			public void KeyUp(KeyEventArgs e)
			{
				this.ShiftKey = ((e.Modifiers & Keys.Shift) == Keys.Shift);
				this.ControlKey = ((e.Modifiers & Keys.Control) == Keys.Control);
			}

			public void DragDrop(DragEventArgs e)
			{
				this.mImageListView.mRenderer.SuspendPaint();
				if (this.selfDragging)
				{
					List<ImageListViewItem> list = new List<ImageListViewItem>();
					int num = -1;
					if (this.DropTarget != null)
					{
						num = this.DropTarget.Index;
					}
					foreach (ImageListViewItem imageListViewItem in this.mImageListView.SelectedItems)
					{
						if (imageListViewItem.Index <= num)
						{
							num--;
						}
						list.Add(imageListViewItem);
						this.mImageListView.Items.RemoveInternal(imageListViewItem, false);
					}
					if (num < 0)
					{
						num = 0;
					}
					if (num > this.mImageListView.Items.Count - 1)
					{
						num = this.mImageListView.Items.Count - 1;
					}
					if (this.DropToRight)
					{
						num++;
					}
					foreach (ImageListViewItem item in list)
					{
						this.mImageListView.Items.InsertInternal(num, item);
						num++;
					}
					this.mImageListView.OnSelectionChangedInternal();
				}
				else
				{
					int num2 = this.mImageListView.Items.Count;
					if (this.DropTarget != null)
					{
						num2 = this.DropTarget.Index;
					}
					if (this.DropToRight)
					{
						num2++;
					}
					if (num2 > this.mImageListView.Items.Count)
					{
						num2 = this.mImageListView.Items.Count;
					}
					string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
					this.mImageListView.OnDropFiles(new DropFileEventArgs(num2, fileNames));
				}
				this.DropTarget = null;
				this.selfDragging = false;
				this.mImageListView.Refresh();
				this.mImageListView.mRenderer.ResumePaint();
			}

			public void DragEnter(DragEventArgs e)
			{
				if (!this.selfDragging && e.Data.GetDataPresent(DataFormats.FileDrop))
				{
					e.Effect = DragDropEffects.Copy;
					return;
				}
				e.Effect = DragDropEffects.None;
			}

			public void DragOver(DragEventArgs e)
			{
				if (this.mImageListView.AllowDrop || (this.mImageListView.AllowDrag && this.selfDragging))
				{
					if (this.mImageListView.Items.Count == 0)
					{
						if (this.selfDragging)
						{
							e.Effect = DragDropEffects.None;
							return;
						}
						e.Effect = DragDropEffects.Copy;
						return;
					}
					else
					{
						System.Drawing.Point p = new System.Drawing.Point(e.X, e.Y);
						p = this.mImageListView.PointToClient(p);
						if (this.mImageListView.ScrollOrientation == ScrollOrientation.VerticalScroll && p.Y > this.mImageListView.ClientRectangle.Bottom - 20)
						{
							this.scrollTimer.Tag = -120;
							this.scrollTimer.Enabled = true;
						}
						else if (this.mImageListView.ScrollOrientation == ScrollOrientation.VerticalScroll && p.Y < this.mImageListView.ClientRectangle.Top + 20)
						{
							this.scrollTimer.Tag = 120;
							this.scrollTimer.Enabled = true;
						}
						else if (this.mImageListView.ScrollOrientation == ScrollOrientation.HorizontalScroll && p.X > this.mImageListView.ClientRectangle.Right - 20)
						{
							this.scrollTimer.Tag = -120;
							this.scrollTimer.Enabled = true;
						}
						else if (this.mImageListView.ScrollOrientation == ScrollOrientation.HorizontalScroll && p.X < this.mImageListView.ClientRectangle.Left + 20)
						{
							this.scrollTimer.Tag = 120;
							this.scrollTimer.Enabled = true;
						}
						else
						{
							this.scrollTimer.Enabled = false;
						}
						p.X -= this.mImageListView.layoutManager.ItemAreaBounds.Left;
						p.Y -= this.mImageListView.layoutManager.ItemAreaBounds.Top;
						bool flag = false;
						int num;
						if (this.mImageListView.ScrollOrientation == ScrollOrientation.HorizontalScroll)
						{
							num = (p.X + this.mImageListView.ViewOffset.X) / this.mImageListView.layoutManager.ItemSizeWithMargin.Width;
						}
						else
						{
							int num2 = p.X / this.mImageListView.layoutManager.ItemSizeWithMargin.Width;
							int num3 = (p.Y + this.mImageListView.ViewOffset.Y) / this.mImageListView.layoutManager.ItemSizeWithMargin.Height;
							if (num2 > this.mImageListView.layoutManager.Cols - 1)
							{
								num2 = this.mImageListView.layoutManager.Cols - 1;
								flag = true;
							}
							num = num3 * this.mImageListView.layoutManager.Cols + num2;
						}
						if (num < 0)
						{
							num = 0;
						}
						if (num > this.mImageListView.Items.Count - 1)
						{
							num = this.mImageListView.Items.Count - 1;
							flag = true;
						}
						ImageListViewItem imageListViewItem = this.mImageListView.Items[num];
						if (this.selfDragging && (imageListViewItem.Selected || (!flag && num > 0 && this.mImageListView.Items[num - 1].Selected) || (flag && num < this.mImageListView.Items.Count - 1 && this.mImageListView.Items[num + 1].Selected)))
						{
							e.Effect = DragDropEffects.None;
							imageListViewItem = null;
						}
						else if (this.selfDragging)
						{
							e.Effect = DragDropEffects.Copy;
						}
						else
						{
							e.Effect = DragDropEffects.Copy;
						}
						if (imageListViewItem != this.DropTarget || flag != this.DropToRight)
						{
							this.DropTarget = imageListViewItem;
							this.DropToRight = flag;
							this.mImageListView.Refresh(true);
							return;
						}
					}
				}
				else
				{
					e.Effect = DragDropEffects.None;
				}
			}

			public void DragLeave()
			{
				if (this.mImageListView.AllowDrag && this.selfDragging)
				{
					this.DropTarget = null;
					this.mImageListView.Refresh(true);
				}
				if (this.scrollTimer.Enabled)
				{
					this.scrollTimer.Enabled = false;
				}
			}

			private void DoHitTest(System.Drawing.Point pt)
			{
				ImageListView.HitInfo hitInfo;
				this.mImageListView.HitTest(pt, out hitInfo);
				if (hitInfo.ItemHit)
				{
					this.HoveredItem = this.mImageListView.Items[hitInfo.ItemIndex];
				}
				else
				{
					this.HoveredItem = null;
				}
				if (hitInfo.ColumnHit)
				{
					this.HoveredColumn = this.mImageListView.Columns[hitInfo.ColumnIndex];
				}
				else
				{
					this.HoveredColumn = null;
				}
				if (hitInfo.ColumnSeparatorHit)
				{
					this.HoveredSeparator = this.mImageListView.Columns[hitInfo.ColumnSeparator];
				}
				else
				{
					this.HoveredSeparator = null;
				}
				if (hitInfo.PaneBorder)
				{
					this.HoveredPaneBorder = true;
				}
				else
				{
					this.HoveredPaneBorder = false;
				}
				this.inItemArea = hitInfo.InItemArea;
				this.inHeaderArea = hitInfo.InHeaderArea;
				this.inPaneArea = hitInfo.InPaneArea;
			}

			private int ApplyNavKey(int index, Keys key)
			{
				if (this.mImageListView.ScrollOrientation == ScrollOrientation.VerticalScroll)
				{
					if (key == Keys.Up && index >= this.mImageListView.layoutManager.Cols)
					{
						index -= this.mImageListView.layoutManager.Cols;
					}
					else if (key == Keys.Down && index < this.mImageListView.Items.Count - this.mImageListView.layoutManager.Cols)
					{
						index += this.mImageListView.layoutManager.Cols;
					}
					else if (key == Keys.Left && index > 0)
					{
						index--;
					}
					else if (key == Keys.Right && index < this.mImageListView.Items.Count - 1)
					{
						index++;
					}
					else if (key == Keys.Prior && index >= this.mImageListView.layoutManager.Cols * (this.mImageListView.layoutManager.Rows - 1))
					{
						index -= this.mImageListView.layoutManager.Cols * (this.mImageListView.layoutManager.Rows - 1);
					}
					else if (key == Keys.Next && index < this.mImageListView.Items.Count - this.mImageListView.layoutManager.Cols * (this.mImageListView.layoutManager.Rows - 1))
					{
						index += this.mImageListView.layoutManager.Cols * (this.mImageListView.layoutManager.Rows - 1);
					}
					else if (key == Keys.Home)
					{
						index = 0;
					}
					else if (key == Keys.End)
					{
						index = this.mImageListView.Items.Count - 1;
					}
				}
				else if (key == Keys.Left && index > 0)
				{
					index--;
				}
				else if (key == Keys.Right && index < this.mImageListView.Items.Count - 1)
				{
					index++;
				}
				else if (key == Keys.Prior && index >= this.mImageListView.layoutManager.Cols)
				{
					index -= this.mImageListView.layoutManager.Cols;
				}
				else if (key == Keys.Next && index < this.mImageListView.Items.Count - this.mImageListView.layoutManager.Cols)
				{
					index += this.mImageListView.layoutManager.Cols;
				}
				else if (key == Keys.Home)
				{
					index = 0;
				}
				else if (key == Keys.End)
				{
					index = this.mImageListView.Items.Count - 1;
				}
				if (index < 0)
				{
					index = 0;
				}
				else if (index > this.mImageListView.Items.Count - 1)
				{
					index = this.mImageListView.Items.Count - 1;
				}
				return index;
			}

			private void scrollTimer_Tick(object sender, EventArgs e)
			{
				int delta = (int)this.scrollTimer.Tag;
				if (this.MouseSelecting)
				{
					System.Drawing.Point point = this.mImageListView.PointToClient(System.Windows.Forms.Control.MousePosition);
					this.mImageListView.OnMouseMove(new MouseEventArgs(System.Windows.Forms.Control.MouseButtons, 0, point.X, point.Y, 0));
				}
				this.mImageListView.OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta));
			}

			private const int SelectionTolerance = 5;

			private ImageListView mImageListView;

			private bool inItemArea;

			private bool inHeaderArea;

			private bool inPaneArea;

			private System.Drawing.Point lastViewOffset;

			private System.Drawing.Point lastSeparatorDragLocation;

			private System.Drawing.Point lastPaneResizeLocation;

			private System.Drawing.Point lastMouseDownLocation;

			private System.Drawing.Point lastMouseMoveLocation;

			private Dictionary<ImageListViewItem, bool> highlightedItems;

			private bool suppressClick;

			private bool lastMouseDownInItemArea;

			private bool lastMouseDownInColumnHeaderArea;

			private bool lastMouseDownInPaneArea;

			private bool lastMouseDownOverItem;

			private bool lastMouseDownOverColumn;

			private bool lastMouseDownOverSeparator;

			private bool lastMouseDownOverPaneBorder;

			private bool selfDragging;

			private Timer scrollTimer;
		}

		public class ImageListViewRenderer : IDisposable
		{
			public ImageListView ImageListView
			{
				get
				{
					return this.mImageListView;
				}
			}

			public bool Clip
			{
				get
				{
					return this.mClip;
				}
				set
				{
					this.mClip = value;
				}
			}

			public ItemDrawOrder ItemDrawOrder
			{
				get
				{
					return this.mItemDrawOrder;
				}
				set
				{
					this.mItemDrawOrder = value;
				}
			}

			public System.Drawing.Rectangle ItemAreaBounds
			{
				get
				{
					return this.mImageListView.layoutManager.ItemAreaBounds;
				}
			}

			public System.Drawing.Rectangle ColumnHeaderBounds
			{
				get
				{
					return this.mImageListView.layoutManager.ColumnHeaderBounds;
				}
			}

			public ImageListViewRenderer()
			{
				this.creatingGraphics = false;
				this.disposed = false;
				this.suspended = false;
				this.suspendCount = 0;
				this.needsPaint = true;
				this.mClip = true;
				this.mItemDrawOrder = ItemDrawOrder.ItemIndex;
			}

			public Image GetImageAsync(ImageListViewItem item, Size size)
			{
				Image rendererImage = this.mImageListView.cacheManager.GetRendererImage(item.Guid, size, this.mImageListView.UseEmbeddedThumbnails);
				if (rendererImage == null)
				{
					this.mImageListView.cacheManager.AddToRendererCache(item.Guid, item.FileName, size, this.mImageListView.UseEmbeddedThumbnails);
				}
				return rendererImage;
			}

			internal void Refresh(Graphics graphics, bool forceUpdate)
			{
				if (forceUpdate || this.CanPaint())
				{
					this.Render(graphics);
					return;
				}
				this.needsPaint = true;
			}

			internal void Refresh(Graphics graphics)
			{
				this.Refresh(graphics, false);
			}

			internal void SuspendPaint(bool ispublic)
			{
				if (ispublic)
				{
					this.suspended = true;
					return;
				}
				this.SuspendPaint();
			}

			internal void ResumePaint(bool ispublic)
			{
				if (ispublic)
				{
					this.suspended = false;
					if (this.needsPaint)
					{
						this.mImageListView.Refresh();
						return;
					}
				}
				else
				{
					this.ResumePaint();
				}
			}

			internal void SuspendPaint()
			{
				if (this.suspendCount == 0)
				{
					this.needsPaint = false;
				}
				this.suspendCount++;
			}

			internal void ResumePaint()
			{
				this.suspendCount--;
				if (this.needsPaint)
				{
					this.mImageListView.Refresh();
				}
			}

			internal bool CanPaint()
			{
				return !this.suspended && this.suspendCount == 0;
			}

			private void Render(Graphics graphics)
			{
				if (this.disposed)
				{
					return;
				}
				if (this.bufferGraphics == null && !this.RecreateBuffer())
				{
					return;
				}
				this.mImageListView.layoutManager.Update();
				Graphics graphics2 = this.bufferGraphics.Graphics;
				graphics2.ResetClip();
				graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
				this.DrawBackground(graphics2, this.mImageListView.layoutManager.ClientArea);
				if (this.mImageListView.View == Autodesk.Revit.DB.View.Details)
				{
					int num = this.mImageListView.layoutManager.ColumnHeaderBounds.Left;
					int top = this.mImageListView.layoutManager.ColumnHeaderBounds.Top;
					int height = this.MeasureColumnHeaderHeight();
					int num2 = 0;
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in this.mImageListView.Columns.GetDisplayedColumns())
					{
						ColumnState columnState = ColumnState.None;
						if (this.mImageListView.navigationManager.HoveredColumn == imageListViewColumnHeader)
						{
							columnState |= ColumnState.Hovered;
						}
						if (this.mImageListView.navigationManager.HoveredSeparator == imageListViewColumnHeader)
						{
							columnState |= ColumnState.SeparatorHovered;
						}
						if (this.mImageListView.navigationManager.SelectedSeperator == imageListViewColumnHeader)
						{
							columnState |= ColumnState.SeparatorSelected;
						}
						System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(num, top, imageListViewColumnHeader.Width, height);
						if (this.mClip)
						{
							System.Drawing.Rectangle clip = System.Drawing.Rectangle.Intersect(rectangle, this.mImageListView.layoutManager.ClientArea);
							graphics2.SetClip(clip);
						}
						else
						{
							graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
						}
						this.DrawColumnHeader(graphics2, imageListViewColumnHeader, columnState, rectangle);
						num += imageListViewColumnHeader.Width;
						num2 = rectangle.Right;
					}
					if (this.mImageListView.Columns.Count != 0)
					{
						if (num2 < this.mImageListView.layoutManager.ClientArea.Right)
						{
							System.Drawing.Rectangle rectangle2 = new System.Drawing.Rectangle(num2, this.mImageListView.layoutManager.ColumnHeaderBounds.Top, this.mImageListView.layoutManager.ClientArea.Right - num2, this.mImageListView.layoutManager.ColumnHeaderBounds.Height);
							if (this.mClip)
							{
								graphics2.SetClip(rectangle2);
							}
							else
							{
								graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
							}
							this.DrawColumnExtender(graphics2, rectangle2);
						}
					}
					else
					{
						System.Drawing.Rectangle columnHeaderBounds = this.mImageListView.layoutManager.ColumnHeaderBounds;
						if (this.mClip)
						{
							graphics2.SetClip(columnHeaderBounds);
						}
						else
						{
							graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
						}
						this.DrawColumnExtender(graphics2, columnHeaderBounds);
					}
				}
				if (this.mImageListView.Items.Count > 0 && (this.mImageListView.View != Autodesk.Revit.DB.View.Details || (this.mImageListView.View == Autodesk.Revit.DB.View.Details && this.mImageListView.Columns.GetDisplayedColumns().Count != 0)) && this.mImageListView.layoutManager.FirstPartiallyVisible != -1 && this.mImageListView.layoutManager.LastPartiallyVisible != -1)
				{
					List<ImageListView.ImageListViewRenderer.DrawItemParams> list = new List<ImageListView.ImageListViewRenderer.DrawItemParams>();
					for (int i = this.mImageListView.layoutManager.FirstPartiallyVisible; i <= this.mImageListView.layoutManager.LastPartiallyVisible; i++)
					{
						ImageListViewItem imageListViewItem = this.mImageListView.Items[i];
						ItemState itemState = ItemState.None;
						ItemHighlightState itemHighlightState = this.mImageListView.navigationManager.HighlightState(imageListViewItem);
						if (itemHighlightState == ItemHighlightState.HighlightedAndSelected || (itemHighlightState == ItemHighlightState.NotHighlighted && imageListViewItem.Selected))
						{
							itemState |= ItemState.Selected;
						}
						if (this.mImageListView.navigationManager.HoveredItem == imageListViewItem && !this.mImageListView.navigationManager.MouseSelecting)
						{
							itemState |= ItemState.Hovered;
						}
						if (imageListViewItem.Focused)
						{
							itemState |= ItemState.Focused;
						}
						System.Drawing.Rectangle itemBounds = this.mImageListView.layoutManager.GetItemBounds(i);
						list.Add(new ImageListView.ImageListViewRenderer.DrawItemParams(imageListViewItem, itemState, itemBounds));
					}
					list.Sort(new ImageListView.ImageListViewRenderer.ItemDrawOrderComparer(this.mItemDrawOrder));
					foreach (ImageListView.ImageListViewRenderer.DrawItemParams drawItemParams in list)
					{
						if (this.mClip)
						{
							System.Drawing.Rectangle clip2 = System.Drawing.Rectangle.Intersect(drawItemParams.Bounds, this.mImageListView.layoutManager.ItemAreaBounds);
							graphics2.SetClip(clip2);
						}
						else
						{
							graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
						}
						this.DrawItem(graphics2, drawItemParams.Item, drawItemParams.State, drawItemParams.Bounds);
					}
				}
				if (this.mImageListView.View == Autodesk.Revit.DB.View.Gallery)
				{
					System.Drawing.Rectangle clientArea = this.mImageListView.layoutManager.ClientArea;
					clientArea.Height -= this.mImageListView.layoutManager.ItemAreaBounds.Height;
					ImageListViewItem imageListViewItem2 = null;
					if (this.mImageListView.Items.FocusedItem != null)
					{
						imageListViewItem2 = this.mImageListView.Items.FocusedItem;
					}
					else if (this.mImageListView.SelectedItems.Count != 0)
					{
						imageListViewItem2 = this.mImageListView.SelectedItems[0];
					}
					else if (this.mImageListView.Items.Count != 0)
					{
						imageListViewItem2 = this.mImageListView.Items[0];
					}
					Image image = null;
					if (imageListViewItem2 != null && clientArea.Width > 4 && clientArea.Height > 4)
					{
						image = this.GetImageAsync(imageListViewItem2, clientArea.Size);
						if (image == null)
						{
							image = imageListViewItem2.ThumbnailImage;
						}
					}
					if (this.mClip)
					{
						graphics2.SetClip(clientArea);
					}
					else
					{
						graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
					}
					this.DrawGalleryImage(graphics2, imageListViewItem2, image, clientArea);
				}
				if (this.mImageListView.View == Autodesk.Revit.DB.View.Pane)
				{
					System.Drawing.Rectangle clientArea2 = this.mImageListView.layoutManager.ClientArea;
					clientArea2.Width = this.mImageListView.mPaneWidth;
					ImageListViewItem imageListViewItem3 = null;
					if (this.mImageListView.Items.FocusedItem != null)
					{
						imageListViewItem3 = this.mImageListView.Items.FocusedItem;
					}
					else if (this.mImageListView.SelectedItems.Count != 0)
					{
						imageListViewItem3 = this.mImageListView.SelectedItems[0];
					}
					else if (this.mImageListView.Items.Count != 0)
					{
						imageListViewItem3 = this.mImageListView.Items[0];
					}
					Image image2 = null;
					if (imageListViewItem3 != null && clientArea2.Width > 4 && clientArea2.Height > 4)
					{
						image2 = this.GetImageAsync(imageListViewItem3, new Size(clientArea2.Width, 65535));
						if (image2 == null)
						{
							image2 = imageListViewItem3.ThumbnailImage;
						}
					}
					if (this.mClip)
					{
						graphics2.SetClip(clientArea2);
					}
					else
					{
						graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
					}
					this.DrawPane(graphics2, imageListViewItem3, image2, clientArea2);
				}
				graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
				this.DrawOverlay(graphics2, this.mImageListView.layoutManager.ClientArea);
				if (this.mImageListView.navigationManager.MouseSelecting)
				{
					System.Drawing.Rectangle selectionRectangle = this.mImageListView.navigationManager.SelectionRectangle;
					if (selectionRectangle.Height > 0 && selectionRectangle.Width > 0)
					{
						if (this.mClip)
						{
							System.Drawing.Rectangle clip3 = new System.Drawing.Rectangle(selectionRectangle.Left, selectionRectangle.Top, selectionRectangle.Width + 1, selectionRectangle.Height + 1);
							graphics2.SetClip(clip3);
						}
						else
						{
							graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
						}
						graphics2.ExcludeClip(this.mImageListView.layoutManager.ColumnHeaderBounds);
						this.DrawSelectionRectangle(graphics2, selectionRectangle);
					}
				}
				if (this.mImageListView.navigationManager.DropTarget != null)
				{
					System.Drawing.Rectangle itemBounds2 = this.mImageListView.layoutManager.GetItemBounds(this.mImageListView.navigationManager.DropTarget.Index);
					if (this.mImageListView.View == Autodesk.Revit.DB.View.Details)
					{
						if (this.mImageListView.navigationManager.DropToRight)
						{
							itemBounds2.Offset(0, this.mImageListView.layoutManager.ItemSizeWithMargin.Height);
						}
						itemBounds2.Offset(0, -1);
						itemBounds2.Height = 2;
					}
					else
					{
						if (this.mImageListView.navigationManager.DropToRight)
						{
							itemBounds2.Offset(this.mImageListView.layoutManager.ItemSizeWithMargin.Width, 0);
						}
						itemBounds2.Offset(-(this.MeasureItemMargin(this.mImageListView.View).Width - 2) / 2 - 2, 0);
						itemBounds2.Width = 2;
					}
					if (this.mClip)
					{
						graphics2.SetClip(itemBounds2);
					}
					else
					{
						graphics2.SetClip(this.mImageListView.layoutManager.ClientArea);
					}
					this.DrawInsertionCaret(graphics2, itemBounds2);
				}
				if (this.mImageListView.hScrollBar.Visible && this.mImageListView.vScrollBar.Visible)
				{
					System.Drawing.Rectangle clientArea3 = this.mImageListView.layoutManager.ClientArea;
					System.Drawing.Rectangle rectangle3 = new System.Drawing.Rectangle(clientArea3.Right, clientArea3.Bottom, this.mImageListView.vScrollBar.Width, this.mImageListView.hScrollBar.Height);
					graphics2.SetClip(rectangle3);
					graphics2.FillRectangle(SystemBrushes.Control, rectangle3);
				}
				this.bufferGraphics.Render(graphics);
			}

			internal bool RecreateBuffer()
			{
				if (this.creatingGraphics)
				{
					return false;
				}
				this.creatingGraphics = true;
				this.bufferContext = BufferedGraphicsManager.Current;
				if (this.disposed)
				{
					throw new ObjectDisposedException("bufferContext");
				}
				int width = Math.Max(this.mImageListView.Width, 1);
				int height = Math.Max(this.mImageListView.Height, 1);
				this.bufferContext.MaximumBuffer = new Size(width, height);
				if (this.bufferGraphics != null)
				{
					this.bufferGraphics.Dispose();
				}
				this.bufferGraphics = this.bufferContext.Allocate(this.mImageListView.CreateGraphics(), new System.Drawing.Rectangle(0, 0, width, height));
				this.creatingGraphics = false;
				this.InitializeGraphics(this.bufferGraphics.Graphics);
				return true;
			}

			void IDisposable.Dispose()
			{
				if (this.disposed)
				{
					return;
				}
				this.disposed = true;
				if (this.bufferGraphics != null)
				{
					this.bufferGraphics.Dispose();
				}
				this.Dispose();
			}

			public virtual void InitializeGraphics(Graphics g)
			{
				g.PixelOffsetMode = PixelOffsetMode.None;
				g.InterpolationMode = InterpolationMode.HighQualityBicubic;
			}

			public virtual int MeasureColumnHeaderHeight()
			{
				if (this.mImageListView.HeaderFont == null)
				{
					return 24;
				}
				return Math.Max(this.mImageListView.HeaderFont.Height + 4, 24);
			}

			public virtual Size MeasureItemMargin(Autodesk.Revit.DB.View view)
			{
				if (view == Autodesk.Revit.DB.View.Details)
				{
					return new Size(2, 0);
				}
				return new Size(4, 4);
			}

			public virtual Size MeasureItem(Autodesk.Revit.DB.View view)
			{
				Size result = default(Size);
				int height = this.mImageListView.Font.Height;
				if (view == Autodesk.Revit.DB.View.Details)
				{
					int num = 0;
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in this.mImageListView.Columns)
					{
						if (imageListViewColumnHeader.Visible)
						{
							num += imageListViewColumnHeader.Width;
						}
					}
					result = new Size(num, height + 2 * height / 6);
				}
				else
				{
					Size sz = new Size(4, 4);
					result = this.mImageListView.ThumbnailSize + sz + sz;
					result.Height += height + Math.Max(4, height / 3);
				}
				return result;
			}

			public virtual void DrawBackground(Graphics g, System.Drawing.Rectangle bounds)
			{
				g.Clear(this.mImageListView.BackColor);
				if (this.ImageListView.BackgroundImage != null)
				{
					Image backgroundImage = this.ImageListView.BackgroundImage;
					if (this.ImageListView.BackgroundImageLayout == ImageLayout.None)
					{
						g.DrawImageUnscaled(backgroundImage, this.ImageListView.layoutManager.ItemAreaBounds.Location);
						return;
					}
					if (this.ImageListView.BackgroundImageLayout == ImageLayout.Center)
					{
						int x = bounds.Left + (bounds.Width - backgroundImage.Width) / 2;
						int y = bounds.Top + (bounds.Height - backgroundImage.Height) / 2;
						g.DrawImageUnscaled(backgroundImage, x, y);
						return;
					}
					if (this.ImageListView.BackgroundImageLayout == ImageLayout.Stretch)
					{
						g.DrawImage(backgroundImage, bounds);
						return;
					}
					if (this.ImageListView.BackgroundImageLayout == ImageLayout.Tile)
					{
						using (Brush brush = new TextureBrush(backgroundImage, WrapMode.Tile))
						{
							g.FillRectangle(brush, bounds);
							return;
						}
					}
					if (this.ImageListView.BackgroundImageLayout == ImageLayout.Zoom)
					{
						float val = (float)bounds.Width / (float)backgroundImage.Width;
						float val2 = (float)bounds.Height / (float)backgroundImage.Height;
						float num = Math.Min(val, val2);
						int num2 = (int)((float)backgroundImage.Width * num);
						int num3 = (int)((float)backgroundImage.Height * num);
						int x2 = bounds.Left + (bounds.Width - num2) / 2;
						int y2 = bounds.Top + (bounds.Height - num3) / 2;
						g.DrawImage(backgroundImage, x2, y2, num2, num3);
					}
				}
			}

			public virtual void DrawSelectionRectangle(Graphics g, System.Drawing.Rectangle selection)
			{
				using (Brush brush = new SolidBrush(System.Drawing.Color.FromArgb(128, SystemColors.Highlight)))
				{
					g.FillRectangle(brush, selection);
					g.DrawRectangle(SystemPens.Highlight, selection);
				}
			}

			public virtual void DrawItem(Graphics g, ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
			{
				Size sz = new Size(4, 4);
				using (Brush brush = new SolidBrush(item.BackColor))
				{
					g.FillRectangle(brush, bounds);
				}
				if ((this.mImageListView.Focused && (state & ItemState.Selected) != ItemState.None) || (!this.mImageListView.Focused && (state & ItemState.Selected) != ItemState.None && (state & ItemState.Hovered) != ItemState.None))
				{
					using (Brush brush2 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(16, SystemColors.Highlight), System.Drawing.Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
					{
						Utility.FillRoundedRectangle(g, brush2, bounds, (this.mImageListView.View == Autodesk.Revit.DB.View.Details) ? 2 : 4);
						goto IL_F3;
					}
				}
				if (!this.mImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
				{
					using (Brush brush3 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(16, SystemColors.GrayText), System.Drawing.Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
					{
						Utility.FillRoundedRectangle(g, brush3, bounds, (this.mImageListView.View == Autodesk.Revit.DB.View.Details) ? 2 : 4);
					}
				}
				IL_F3:
				if ((state & ItemState.Hovered) != ItemState.None)
				{
					using (Brush brush4 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(8, SystemColors.Highlight), System.Drawing.Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
					{
						Utility.FillRoundedRectangle(g, brush4, bounds, (this.mImageListView.View == Autodesk.Revit.DB.View.Details) ? 2 : 4);
					}
				}
				if (this.mImageListView.View != Autodesk.Revit.DB.View.Details)
				{
					Image thumbnailImage = item.ThumbnailImage;
					if (thumbnailImage == null)
					{
						goto IL_50A;
					}
					System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(thumbnailImage, new System.Drawing.Rectangle(bounds.Location + sz, this.mImageListView.ThumbnailSize));
					g.DrawImage(thumbnailImage, sizedImageBounds);
					if (Math.Min(sizedImageBounds.Width, sizedImageBounds.Height) <= 32)
					{
						goto IL_50A;
					}
					using (Pen pen = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.Gray)))
					{
						g.DrawRectangle(pen, sizedImageBounds);
					}
					if (Math.Min(this.mImageListView.ThumbnailSize.Width, this.mImageListView.ThumbnailSize.Height) <= 32)
					{
						goto IL_50A;
					}
					using (Pen pen2 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
					{
						g.DrawRectangle(pen2, System.Drawing.Rectangle.Inflate(sizedImageBounds, -1, -1));
						goto IL_50A;
					}
				}
				List<ImageListView.ImageListViewColumnHeader> displayedColumns = this.mImageListView.Columns.GetDisplayedColumns();
				int num = this.mImageListView.layoutManager.ColumnHeaderBounds.Left;
				foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in displayedColumns)
				{
					if (this.mImageListView.SortColumn == imageListViewColumnHeader.Type && this.mImageListView.SortOrder != SortOrder.None && (state & ItemState.Hovered) == ItemState.None && (state & ItemState.Selected) == ItemState.None)
					{
						System.Drawing.Rectangle rect = bounds;
						rect.X = num;
						rect.Width = imageListViewColumnHeader.Width;
						using (Brush brush5 = new SolidBrush(System.Drawing.Color.FromArgb(16, SystemColors.GrayText)))
						{
							g.FillRectangle(brush5, rect);
							break;
						}
					}
					num += imageListViewColumnHeader.Width;
				}
				num = this.mImageListView.layoutManager.ColumnHeaderBounds.Left;
				foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader2 in displayedColumns)
				{
					num += imageListViewColumnHeader2.Width;
					if (imageListViewColumnHeader2 != displayedColumns[displayedColumns.Count - 1])
					{
						using (Pen pen3 = new Pen(System.Drawing.Color.FromArgb(32, SystemColors.GrayText)))
						{
							g.DrawLine(pen3, num, bounds.Top, num, bounds.Bottom);
						}
					}
				}
				Size size = new Size(2, (bounds.Height - this.mImageListView.Font.Height) / 2);
				using (StringFormat stringFormat = new StringFormat())
				{
					stringFormat.FormatFlags = StringFormatFlags.NoWrap;
					stringFormat.Alignment = StringAlignment.Near;
					stringFormat.LineAlignment = StringAlignment.Center;
					stringFormat.Trimming = StringTrimming.EllipsisCharacter;
					RectangleF layoutRectangle = new RectangleF((float)(bounds.Left + size.Width), (float)(bounds.Top + size.Height), (float)(displayedColumns[0].Width - 2 * size.Width), (float)(bounds.Height - 2 * size.Height));
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader3 in displayedColumns)
					{
						layoutRectangle.Width = (float)(imageListViewColumnHeader3.Width - 2 * size.Width);
						using (Brush brush6 = new SolidBrush(item.ForeColor))
						{
							g.DrawString(item.GetSubItemText(imageListViewColumnHeader3.Type), this.mImageListView.Font, brush6, layoutRectangle, stringFormat);
						}
						layoutRectangle.X += (float)imageListViewColumnHeader3.Width;
					}
				}
				IL_50A:
				using (Pen pen4 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
				{
					Utility.DrawRoundedRectangle(g, pen4, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, (this.mImageListView.View == Autodesk.Revit.DB.View.Details) ? 2 : 4);
				}
				if (this.mImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
				{
					using (Pen pen5 = new Pen(System.Drawing.Color.FromArgb(128, SystemColors.Highlight)))
					{
						Utility.DrawRoundedRectangle(g, pen5, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, (this.mImageListView.View == Autodesk.Revit.DB.View.Details) ? 2 : 4);
						goto IL_6B9;
					}
				}
				if (!this.mImageListView.Focused && (state & ItemState.Selected) != ItemState.None)
				{
					using (Pen pen6 = new Pen(System.Drawing.Color.FromArgb(128, SystemColors.GrayText)))
					{
						Utility.DrawRoundedRectangle(g, pen6, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, (this.mImageListView.View == Autodesk.Revit.DB.View.Details) ? 2 : 4);
						goto IL_6B9;
					}
				}
				if (this.mImageListView.View == Autodesk.Revit.DB.View.Thumbnails && (state & ItemState.Selected) == ItemState.None)
				{
					using (Pen pen7 = new Pen(System.Drawing.Color.FromArgb(64, SystemColors.GrayText)))
					{
						Utility.DrawRoundedRectangle(g, pen7, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, (this.mImageListView.View == Autodesk.Revit.DB.View.Details) ? 2 : 4);
					}
				}
				IL_6B9:
				if (this.mImageListView.Focused && (state & ItemState.Hovered) != ItemState.None)
				{
					using (Pen pen8 = new Pen(System.Drawing.Color.FromArgb(64, SystemColors.Highlight)))
					{
						Utility.DrawRoundedRectangle(g, pen8, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, (this.mImageListView.View == Autodesk.Revit.DB.View.Details) ? 2 : 4);
					}
				}
				if (this.mImageListView.Focused && (state & ItemState.Focused) != ItemState.None)
				{
					ControlPaint.DrawFocusRectangle(g, bounds);
				}
			}

			public virtual void DrawColumnHeader(Graphics g, ImageListView.ImageListViewColumnHeader column, ColumnState state, System.Drawing.Rectangle bounds)
			{
				if (this.mImageListView.Focused && (state & ColumnState.Hovered) == ColumnState.Hovered)
				{
					using (Brush brush = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(16, SystemColors.Highlight), System.Drawing.Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
					{
						g.FillRectangle(brush, bounds);
						goto IL_82;
					}
				}
				using (Brush brush2 = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(32, SystemColors.Control), System.Drawing.Color.FromArgb(196, SystemColors.Control), LinearGradientMode.Vertical))
				{
					g.FillRectangle(brush2, bounds);
				}
				IL_82:
				using (Brush brush3 = new LinearGradientBrush(bounds, SystemColors.ControlLightLight, SystemColors.ControlDark, LinearGradientMode.Vertical))
				{
					using (Pen pen = new Pen(brush3))
					{
						g.DrawLine(pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
						g.DrawLine(pen, bounds.Left, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
					}
				}
				g.DrawLine(SystemPens.ControlLightLight, bounds.Left + 1, bounds.Top + 1, bounds.Left + 1, bounds.Bottom - 2);
				g.DrawLine(SystemPens.ControlLightLight, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 2);
				int num = 4;
				if (this.mImageListView.SortOrder != SortOrder.None && this.mImageListView.SortColumn == column.Type)
				{
					Image image = null;
					if (this.mImageListView.SortOrder == SortOrder.Ascending)
					{
						image = ImageListViewResources.SortAscending;
					}
					else if (this.mImageListView.SortOrder == SortOrder.Descending)
					{
						image = ImageListViewResources.SortDescending;
					}
					g.DrawImageUnscaled(image, bounds.X + 4, bounds.Top + (bounds.Height - image.Height) / 2);
					num += image.Width;
				}
				bounds.X += num;
				bounds.Width -= num;
				if (bounds.Width > 4)
				{
					using (StringFormat stringFormat = new StringFormat())
					{
						stringFormat.FormatFlags = StringFormatFlags.NoWrap;
						stringFormat.Alignment = StringAlignment.Near;
						stringFormat.LineAlignment = StringAlignment.Center;
						stringFormat.Trimming = StringTrimming.EllipsisCharacter;
						g.DrawString(column.Text, (this.mImageListView.HeaderFont == null) ? this.mImageListView.Font : this.mImageListView.HeaderFont, SystemBrushes.WindowText, bounds, stringFormat);
					}
				}
			}

			public virtual void DrawPane(Graphics g, ImageListViewItem item, Image image, System.Drawing.Rectangle bounds)
			{
				using (Brush brush = new SolidBrush(System.Drawing.Color.FromArgb(16, SystemColors.GrayText)))
				{
					g.FillRectangle(brush, bounds);
				}
				using (Brush brush2 = new SolidBrush(System.Drawing.Color.FromArgb(128, SystemColors.GrayText)))
				{
					g.FillRectangle(brush2, bounds.Right - 2, bounds.Top, 2, bounds.Height);
				}
				bounds.Width -= 2;
				if (item != null && image != null)
				{
					Size size = this.MeasureItemMargin(this.mImageListView.View);
					System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(image, new System.Drawing.Rectangle(bounds.Location + size, bounds.Size - size - size), 50f, 0f);
					g.DrawImage(image, sizedImageBounds);
					if (Math.Min(sizedImageBounds.Width, sizedImageBounds.Height) > 32)
					{
						using (Pen pen = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.Gray)))
						{
							g.DrawRectangle(pen, sizedImageBounds);
						}
						using (Pen pen2 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
						{
							g.DrawRectangle(pen2, System.Drawing.Rectangle.Inflate(sizedImageBounds, -1, -1));
						}
					}
					bounds.X += size.Width;
					bounds.Width -= 2 * size.Width;
					bounds.Y = sizedImageBounds.Height + 16;
					bounds.Height -= sizedImageBounds.Height + 16;
					if (this.mImageListView.Columns[ColumnType.Name].Visible && bounds.Height > 0)
					{
						int num = Utility.DrawStringPair(g, bounds, "", item.Text, this.mImageListView.Font, SystemBrushes.GrayText, SystemBrushes.WindowText);
						bounds.Y += 2 * num;
						bounds.Height -= 2 * num;
					}
					if (this.mImageListView.Columns[ColumnType.FileType].Visible && bounds.Height > 0 && !string.IsNullOrEmpty(item.FileType))
					{
						int num2 = Utility.DrawStringPair(g, bounds, this.mImageListView.Columns[ColumnType.FileType].Text + ": ", item.FileType, this.mImageListView.Font, SystemBrushes.GrayText, SystemBrushes.WindowText);
						bounds.Y += num2;
						bounds.Height -= num2;
					}
					foreach (ImageListView.ImageListViewColumnHeader imageListViewColumnHeader in this.mImageListView.Columns)
					{
						if (imageListViewColumnHeader.Type == ColumnType.ImageDescription)
						{
							bounds.Y += 8;
							bounds.Height -= 8;
						}
						if (bounds.Height <= 0)
						{
							break;
						}
						if (imageListViewColumnHeader.Visible && imageListViewColumnHeader.Type != ColumnType.FileType && imageListViewColumnHeader.Type != ColumnType.DateAccessed && imageListViewColumnHeader.Type != ColumnType.FileName && imageListViewColumnHeader.Type != ColumnType.FilePath && imageListViewColumnHeader.Type != ColumnType.Name)
						{
							string text = imageListViewColumnHeader.Text;
							string subItemText = item.GetSubItemText(imageListViewColumnHeader.Type);
							if (!string.IsNullOrEmpty(subItemText))
							{
								int num3 = Utility.DrawStringPair(g, bounds, text + ": ", subItemText, this.mImageListView.Font, SystemBrushes.GrayText, SystemBrushes.WindowText);
								bounds.Y += num3;
								bounds.Height -= num3;
							}
						}
					}
				}
			}

			public virtual void DrawGalleryImage(Graphics g, ImageListViewItem item, Image image, System.Drawing.Rectangle bounds)
			{
				if (item != null && image != null)
				{
					Size size = this.MeasureItemMargin(this.mImageListView.View);
					System.Drawing.Rectangle sizedImageBounds = Utility.GetSizedImageBounds(image, new System.Drawing.Rectangle(bounds.Location + size, bounds.Size - size - size));
					g.DrawImage(image, sizedImageBounds);
					if (Math.Min(sizedImageBounds.Width, sizedImageBounds.Height) > 32)
					{
						using (Pen pen = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.Gray)))
						{
							g.DrawRectangle(pen, sizedImageBounds);
						}
						using (Pen pen2 = new Pen(System.Drawing.Color.FromArgb(128, System.Drawing.Color.White)))
						{
							g.DrawRectangle(pen2, System.Drawing.Rectangle.Inflate(sizedImageBounds, -1, -1));
						}
					}
				}
			}

			public virtual void DrawColumnExtender(Graphics g, System.Drawing.Rectangle bounds)
			{
				using (Brush brush = new LinearGradientBrush(bounds, System.Drawing.Color.FromArgb(32, SystemColors.Control), System.Drawing.Color.FromArgb(196, SystemColors.Control), LinearGradientMode.Vertical))
				{
					g.FillRectangle(brush, bounds);
				}
				using (Brush brush2 = new LinearGradientBrush(bounds, SystemColors.ControlLightLight, SystemColors.ControlDark, LinearGradientMode.Vertical))
				{
					using (Pen pen = new Pen(brush2))
					{
						g.DrawLine(pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom);
						g.DrawLine(pen, bounds.Left, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
					}
				}
				g.DrawLine(SystemPens.ControlLightLight, bounds.Left + 1, bounds.Top + 1, bounds.Left + 1, bounds.Bottom - 2);
				g.DrawLine(SystemPens.ControlLightLight, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 2);
			}

			public virtual void DrawInsertionCaret(Graphics g, System.Drawing.Rectangle bounds)
			{
				using (Brush brush = new SolidBrush(SystemColors.Highlight))
				{
					g.FillRectangle(brush, bounds);
				}
			}

			public virtual void DrawOverlay(Graphics g, System.Drawing.Rectangle bounds)
			{
			}

			public virtual void Dispose()
			{
			}

			public virtual void OnLayout(LayoutEventArgs e)
			{
			}

			private bool mClip;

			internal ImageListView mImageListView;

			private BufferedGraphicsContext bufferContext;

			private BufferedGraphics bufferGraphics;

			private bool disposed;

			private bool suspended;

			private int suspendCount;

			private bool needsPaint;

			private ItemDrawOrder mItemDrawOrder;

			private bool creatingGraphics;

			private struct DrawItemParams
			{
				public DrawItemParams(ImageListViewItem item, ItemState state, System.Drawing.Rectangle bounds)
				{
					this.Item = item;
					this.State = state;
					this.Bounds = bounds;
				}

				public ImageListViewItem Item;

				public ItemState State;

				public System.Drawing.Rectangle Bounds;
			}

			private class ItemDrawOrderComparer : IComparer<ImageListView.ImageListViewRenderer.DrawItemParams>
			{
				public ItemDrawOrderComparer(ItemDrawOrder drawOrder)
				{
					this.mDrawOrder = drawOrder;
				}

				public int Compare(ImageListView.ImageListViewRenderer.DrawItemParams param1, ImageListView.ImageListViewRenderer.DrawItemParams param2)
				{
					if (param1 == param2)
					{
						return 0;
					}
					if (param1.Item == param2.Item)
					{
						return 0;
					}
					if (this.mDrawOrder == ItemDrawOrder.ItemIndex)
					{
						return this.CompareByIndex(param1, param2);
					}
					if (this.mDrawOrder == ItemDrawOrder.ZOrder)
					{
						return this.CompareByZOrder(param1, param2);
					}
					int num;
					if (this.mDrawOrder == ItemDrawOrder.NormalSelectedHovered)
					{
						num = -this.CompareByHovered(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareBySelected(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareByNormal(param1, param2);
						if (num != 0)
						{
							return num;
						}
					}
					else if (this.mDrawOrder == ItemDrawOrder.NormalHoveredSelected)
					{
						num = -this.CompareBySelected(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareByHovered(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareByNormal(param1, param2);
						if (num != 0)
						{
							return num;
						}
					}
					else if (this.mDrawOrder == ItemDrawOrder.SelectedNormalHovered)
					{
						num = -this.CompareByHovered(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareByNormal(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareBySelected(param1, param2);
						if (num != 0)
						{
							return num;
						}
					}
					else if (this.mDrawOrder == ItemDrawOrder.SelectedHoveredNormal)
					{
						num = -this.CompareByNormal(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareByHovered(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareBySelected(param1, param2);
						if (num != 0)
						{
							return num;
						}
					}
					else if (this.mDrawOrder == ItemDrawOrder.HoveredNormalSelected)
					{
						num = -this.CompareBySelected(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareByNormal(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareByHovered(param1, param2);
						if (num != 0)
						{
							return num;
						}
					}
					else if (this.mDrawOrder == ItemDrawOrder.HoveredSelectedNormal)
					{
						num = -this.CompareByNormal(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareBySelected(param1, param2);
						if (num != 0)
						{
							return num;
						}
						num = -this.CompareByHovered(param1, param2);
						if (num != 0)
						{
							return num;
						}
					}
					num = this.CompareByZOrder(param1, param2);
					if (num != 0)
					{
						return num;
					}
					return this.CompareByIndex(param1, param2);
				}

				private int CompareByIndex(ImageListView.ImageListViewRenderer.DrawItemParams param1, ImageListView.ImageListViewRenderer.DrawItemParams param2)
				{
					if (param1.Item.Index < param2.Item.Index)
					{
						return -1;
					}
					if (param1.Item.Index > param2.Item.Index)
					{
						return 1;
					}
					return 0;
				}

				private int CompareByZOrder(ImageListView.ImageListViewRenderer.DrawItemParams param1, ImageListView.ImageListViewRenderer.DrawItemParams param2)
				{
					if (param1.Item.ZOrder < param2.Item.ZOrder)
					{
						return -1;
					}
					if (param1.Item.ZOrder > param2.Item.ZOrder)
					{
						return 1;
					}
					return 0;
				}

				private int CompareByNormal(ImageListView.ImageListViewRenderer.DrawItemParams param1, ImageListView.ImageListViewRenderer.DrawItemParams param2)
				{
					if (param1.State == ItemState.None && param2.State != ItemState.None)
					{
						return -1;
					}
					if (param1.State != ItemState.None && param2.State == ItemState.None)
					{
						return 1;
					}
					return 0;
				}

				private int CompareBySelected(ImageListView.ImageListViewRenderer.DrawItemParams param1, ImageListView.ImageListViewRenderer.DrawItemParams param2)
				{
					if ((param1.State & ItemState.Selected) == ItemState.Selected && (param2.State & ItemState.Selected) != ItemState.Selected)
					{
						return -1;
					}
					if ((param1.State & ItemState.Selected) != ItemState.Selected && (param2.State & ItemState.Selected) == ItemState.Selected)
					{
						return 1;
					}
					return 0;
				}

				private int CompareByHovered(ImageListView.ImageListViewRenderer.DrawItemParams param1, ImageListView.ImageListViewRenderer.DrawItemParams param2)
				{
					if ((param1.State & ItemState.Hovered) == ItemState.Hovered)
					{
						return -1;
					}
					if ((param2.State & ItemState.Hovered) == ItemState.Hovered)
					{
						return 1;
					}
					return 0;
				}

				private int CompareByFocused(ImageListView.ImageListViewRenderer.DrawItemParams param1, ImageListView.ImageListViewRenderer.DrawItemParams param2)
				{
					if ((param1.State & ItemState.Focused) == ItemState.Focused)
					{
						return -1;
					}
					if ((param2.State & ItemState.Focused) == ItemState.Focused)
					{
						return 1;
					}
					return 0;
				}

				private ItemDrawOrder mDrawOrder;
			}
		}

		public class ImageListViewSelectedItemCollection : IList<ImageListViewItem>, ICollection<ImageListViewItem>, IEnumerable<ImageListViewItem>, IEnumerable
		{
			internal ImageListViewSelectedItemCollection(ImageListView owner)
			{
				this.mImageListView = owner;
			}

			[Category("Behavior")]
			[Browsable(true)]
			[Description("Gets the number of elements contained in the collection.")]
			public int Count
			{
				get
				{
					int num = 0;
					IEnumerator<ImageListViewItem> enumerator = this.mImageListView.mItems.GetEnumerator();
					{
						while (enumerator.MoveNext())
						{
							if (enumerator.Current.Selected)
							{
								num++;
							}
						}
					}
					return num;
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets a value indicating whether the collection is read-only.")]
			public bool IsReadOnly
			{
				get
				{
					return true;
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets the ImageListView owning this collection.")]
			public ImageListView ImageListView
			{
				get
				{
					return this.mImageListView;
				}
			}

			[Category("Behavior")]
			[Browsable(false)]
			[Description("Gets or sets the item at the specified index")]
			public ImageListViewItem this[int index]
			{
				get
				{
					int num = 0;
					foreach (ImageListViewItem result in this)
					{
						if (num == index)
						{
							return result;
						}
						num++;
					}
					throw new ArgumentException("No item with the given index exists.", "index");
				}
			}

			public bool Contains(ImageListViewItem item)
			{
				return item.Selected && this.mImageListView.Items.Contains(item);
			}

			public IEnumerator<ImageListViewItem> GetEnumerator()
			{
				return new ImageListView.ImageListViewSelectedItemCollection.ImageListViewSelectedItemEnumerator(this.mImageListView.mItems);
			}

			IEnumerator IEnumerable.GetEnumerator()
			{
				return this.GetEnumerator();
			}

			internal void Clear()
			{
				this.Clear(true);
			}

			internal void Clear(bool raiseEvent)
			{
				foreach (ImageListViewItem imageListViewItem in this)
				{
					imageListViewItem.mSelected = false;
				}
				if (raiseEvent && this.mImageListView != null)
				{
					this.mImageListView.OnSelectionChangedInternal();
				}
			}

			void ICollection<ImageListViewItem>.Add(ImageListViewItem item)
			{
				throw new NotSupportedException();
			}

			void ICollection<ImageListViewItem>.Clear()
			{
				throw new NotSupportedException();
			}

			void ICollection<ImageListViewItem>.CopyTo(ImageListViewItem[] array, int arrayIndex)
			{
				throw new NotSupportedException();
			}

			[Obsolete("Use ImageListViewItem.Index property instead.")]
			int IList<ImageListViewItem>.IndexOf(ImageListViewItem item)
			{
				throw new NotSupportedException();
			}

			void IList<ImageListViewItem>.Insert(int index, ImageListViewItem item)
			{
				throw new NotSupportedException();
			}

			bool ICollection<ImageListViewItem>.Remove(ImageListViewItem item)
			{
				throw new NotSupportedException();
			}

			void IList<ImageListViewItem>.RemoveAt(int index)
			{
				throw new NotSupportedException();
			}

			ImageListViewItem IList<ImageListViewItem>.this[int index]
			{
				get
				{
					throw new NotSupportedException();
				}
				set
				{
					throw new NotSupportedException();
				}
			}

			internal ImageListView mImageListView;

			internal class ImageListViewSelectedItemEnumerator : IEnumerator<ImageListViewItem>, IDisposable, IEnumerator
			{
				public ImageListViewSelectedItemEnumerator(ImageListView.ImageListViewItemCollection collection)
				{
					this.owner = collection;
					this.current = -1;
					this.lastItem = Guid.Empty;
				}

				public ImageListViewItem Current
				{
					get
					{
						if (this.current == -1 || this.current > this.owner.Count - 1)
						{
							throw new Autodesk.Revit.Exceptions.InvalidOperationException();
						}
						return this.owner[this.current];
					}
				}

				object IEnumerator.Current
				{
					get
					{
						return this.Current;
					}
				}

				public void Dispose()
				{
				}

				public bool MoveNext()
				{
					if (this.current > this.owner.Count - 1)
					{
						this.lastItem = Guid.Empty;
						return false;
					}
					while (this.current == -1 || this.owner[this.current].Guid == this.lastItem || !this.owner[this.current].Selected)
					{
						this.current++;
						if (this.current > this.owner.Count - 1)
						{
							this.lastItem = Guid.Empty;
							return false;
						}
					}
					this.lastItem = this.owner[this.current].Guid;
					return true;
				}

				public void Reset()
				{
					this.current = -1;
					this.lastItem = Guid.Empty;
				}

				private ImageListView.ImageListViewItemCollection owner;

				private int current;

				private Guid lastItem;
			}
		}
	}
}
